Setting Up a Local GitLab Runner on Linux machine and Configuring the runner on Gitlab Pipeline.

Setting Up a Local GitLab Runner on Linux machine and Configuring  the 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:

  1. On the left sidebar, at the bottom, select Admin Area.

  2. Select CI/CD > Runners.

  3. Select New instance runner.

  4. Select the operating system where GitLab Runner is installed.

  5. 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.

  6. Optional. In the Runner description field, to add a runner description that displays in GitLab, enter a runner description.

  7. Optional. In the Configuration section, add additional configurations.

  8. Select Create runner.

Step 6. Register a runner.

Prerequisites:

  • Obtain a runner authentication token. You can either:

sudo gitlab-runner register

Enter Gitlab instance URL :- 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.