Setting Up a Local GitLab Runner on Linux machine and Configuring the runner on Gitlab Pipeline.
Table of contents
- What is Gitlab Runner ?
- How to install Gitlab-runner on linux (Ubuntu) 64-bit machine ?
- Step 1. Run this command on your Linux terminal:
- Step 2. Give it permissions to execute:
- Step 3.Create a GitLab CI user:
- Step 4.Install and run as service:
- Step 5.Generate runner authentication token
- Step 6. Register a runner.
- Step 7. How to configure gitlab-runner on gitlab pipeline ?
What is Gitlab Runner ?
GitLab Runner is an application that works with GitLab CI/CD to run jobs in a pipeline.
How to install Gitlab-runner on linux (Ubuntu) 64-bit machine ?
Step 1. Run this command on your Linux terminal:
sudo curl -L --output /usr/local/bin/gitlab-runner https://s3.dualstack.us-east-1.amazonaws.com/gitlab-runner-downloads/latest/binaries/gitlab-runner-linux-amd64
Step 2. Give it permissions to execute:
sudo chmod +x /usr/local/bin/gitlab-runner
Step 3.Create a GitLab CI user:
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
Step 4.Install and run as service:
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
Step 5.Generate runner authentication token
How to generate runner authentication token on gitlab ?
To create an instance runner:
On the left sidebar, at the bottom, select Admin Area.
Select CI/CD > Runners.
Select New instance runner.
Select the operating system where GitLab Runner is installed.
In the Tags section, in the Tags field, enter the job tags to specify jobs the runner can run. If there are no job tags for this runner, select Run untagged.
Optional. In the Runner description field, to add a runner description that displays in GitLab, enter a runner description.
Optional. In the Configuration section, add additional configurations.
Select Create runner.
Step 6. Register a runner.
Prerequisites:
sudo gitlab-runner register
Enter Gitlab instance URL :- https://gitlab.com/
Then Enter Gitlab Runner Authentication Token and select executor.
Please follow this document to setup executors during registering a runner**.**
https://docs.gitlab.com/runner/executors/
Step 7. How to configure gitlab-runner on gitlab pipeline ?
When you register a runner, you can add tags to it.
When a CI/CD job runs, it knows which runner to use by looking at the assigned tags. Tags are the only way to filter the list of available runners for a job.
For example, if a runner has the build
tag, you would add this code to your project’s .gitlab-ci.yml
file:
In gitlab project Navigate to gitlab.ci.yml configure this command:
tags:
- Build
Example:-
Important note: Tag should be same in runner and gitlab.ci.yml.
Subscribe to my newsletter
Read articles from Ritik Ranjan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by