Install GitLab Runner on Ubuntu 20.04

GitLab CI/CD is a part of GitLab for applications development using continuous integration (CI) and continuous delivery (CD) techniques. GitLab Runner is a tool for running jobs in a pipeline. GitLab Runner works with GitLab CI/CD.

This tutorial demonstrates how to install GitLab Runner on Ubuntu 20.04.

Prepare environment

Before starting, make sure you have installed GitLab CE on your system.

Install GitLab Runner

Add the GitLab Runner repository:

wget -qO - | sudo bash

Install the GitLab Runner:

sudo apt install -y gitlab-runner

When the installation is finished, we can check version of GitLab Runner:

gitlab-runner --version

Register runner

GitLab Runner supports various executors to run jobs in a pipeline. It is possible use of Docker executor. Before registering a runner, make sure you have installed Docker CE on your system.

GitLab Runner can be registered as shared runner or project-specific runner. A shared runner can run jobs for all projects. A specific runner can run jobs for the specified project. Before registration, we need to get token:

  • For a shared runner, login to GitLab website with administrator account and go to Admin Area. Click "Overview" and then "Runners".
Shared runner registration
  • For a project-specific runner, login to GitLab website and go to project page. Click "Settings" and then "CI/CD". Expand the Runners section.
Project-specific runner registration

GitLab Runner can be registered using the following command:

sudo gitlab-runner register \
  --non-interactive \
  --url "GITLAB_URL" \
  --registration-token "REGISTRATION_TOKEN" \
  --description "docker-runner" \
  --executor "docker" \
  --docker-image ubuntu:latest

Provide GitLab instance URL and registration token. In our case, we chosen ubuntu:latest as default image to be used for projects.

Uninstall GitLab Runner

If you want to completely remove GitLab Runner, run the following command:

sudo apt purge --autoremove -y gitlab-runner

Remove GPG key and repository:

sudo apt-key del 51312F3F
sudo rm -rf /etc/apt/sources.list.d/runner_gitlab-runner.list

Remove GitLab Runner user:

sudo deluser --remove-home gitlab-runner

You can also remove GitLab Runner configuration:

sudo rm -rf /etc/gitlab-runner

Leave a Comment

Your email address will not be published.