How to install configure and register GitLab runner?
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
Today we will discuss how to install, configure and register a GitLab runner into a GitLab project to run your CI/CD pipelines in your own specific or group runner.
Prerequisites:
- One GitLab project with maintainer access.
How to install configure and add GitLab runner?
GitLab Runner Installation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
## -------- ## Linux OS ## -------- ## Download the binary for your system sudo curl -L --output /usr/local/bin/gitlab-runner \ https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64 ## Give it permissions to execute sudo chmod +x /usr/local/bin/gitlab-runner ## Create a GitLab CI user sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash ## Install and run as service sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner sudo gitlab-runner start ## Check if the installation was successful gitlab-runner --version ## ------ ## MAC OS ## ------ ## Download the binary for your system sudo curl --output /usr/local/bin/gitlab-runner \ https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64 ## Give it permissions to execute sudo chmod +x /usr/local/bin/gitlab-runner ## Install and run as service cd ~ gitlab-runner install gitlab-runner start ## Check if the installation was successful gitlab-runner --version ## ---------- ## Windows OS ## ---------- ## Open a PowerShell session as admin ## Create a folder somewhere in your system ex.: C:\GitLab-Runner New-Item -Path 'C:\GitLab-Runner' -ItemType Directory ## Enter the folder cd 'C:\GitLab-Runner' ## Dowload binary Invoke-WebRequest -Uri "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-windows-amd64.exe" ` -OutFile "gitlab-runner.exe" ## Install and run as service .\gitlab-runner.exe install .\gitlab-runner.exe start ## Check if the installation was successful gitlab-runner --version |
Next, we will register the GitLab runner.
GitLab Runner Registration:
Step 1: Login to your GitLab account => Select the project => Settings => CI/CD => Runners (Click Expand).
Step 2: Copy the Gitlab URL and registration token.
Step 3: Register GitLab Runner:
Open a terminal on the system where you have installed GitLab runner and execute below command to register the GitLab runner.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
## ---------------------- ## Register GitLab Runner ## ---------------------- ## Register runner with "shell" executor sudo gitlab-runner register \ --non-interactive \ --url "https://gitlab.com/" \ --registration-token " --executor "shell" \ --description "shell-runner" \ --tag-list "shell,aws" \ --run-untagged="true" \ --locked="false" \ --access-level="not_protected" ## Register runner with "docker" executor sudo gitlab-runner register \ --non-interactive \ --url "https://gitlab.com/" \ --registration-token " --executor "docker" \ --docker-image alpine:latest \ --description "docker-runner" \ --tag-list "docker,aws" \ --run-untagged="true" \ --locked="false" \ --access-level="not_protected" ## Replace \ with ` for windows os ## For docker executor, docker needs to be installed first |
If you refresh the GitLab Project CI/CD Runner settings page, you will be able to view your runner listed in GitLab.
You can also test your runner by executing a CI/CD pipeline in your GitLab runner using the tag. Below is an example .gitlab-ci.yml file for your reference –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
## cat .gitlab-ci.yml stages: - build - test - deploy project_build: stage: build tags: - cloudaffaire script: - echo "this is a build job" project_test: stage: test tags: - cloudaffaire script: - echo "this is a test job" project_deploy: stage: deploy tags: - cloudaffaire script: - echo "this is a deploy job" |
Note: Replace the tags as per the value used in –tag-list during runner registration.
Hope you have enjoyed this article, to get more details on GitLab and GitLab runner follow below link.