How to Install GitLab Runner on Ubuntu 20.04 LTS

In this article we are going to cover How to Install GitLab Runner on Ubuntu 20.04 LTS / any other cloud platform like AWS EC2, Azure VM, Google Cloud with preinstalled Ubuntu 20.04 LTS.

Step #1: Add the Official GitLab Repository

First add the official GitLab Repository using below command, to check latest Gitlab Repository visit the official GitLab Runner page

curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash

Step #2: Install GitLab Runner on Ubuntu

Run below command to install latest GitLab Runner on Ubuntu 20.04 LTS

sudo apt-get install gitlab-runner

use below commands to install specific version of GitLab Runner on Ubuntu.

apt-cache madison gitlab-runner
sudo apt-get install gitlab-runner=10.0.0

Command to check GitLab Runner version

sudo gitlab-runner -version

Output:

Version:      13.4.1
Git revision: e95f89a0
Git branch:   13-4-stable
GO version:   go1.13.8
Built:        2020-09-25T20:03:43+0000
OS/Arch:      linux/amd64

To check status if GitLab Runner service is running or not

sudo gitlab-runner status

Output:

Runtime platform                                    arch=amd64 os=linux pid=29368 revision=e95f89a0 version=13.4.1
gitlab-runner: Service is running!

Commands to Start, Stop and Restart GitLab Runner

sudo gitlab-runner start
sudo gitlab-runner stop
sudo gitlab-runner restart

Step #3: Grant sudo Permission to GitLab Runner User

After install GitLab Runner you will see gitlab-runner user in /home directory

cd /home
ls

Output:

gitlab-runner ubuntu

To grant sudo permission to gitlab-runner user, ope the visudo file

sudo visudo

Add the gitlab-runner user in sudoers group and set NOPASSWD as shown below

gitlab-runner ALL=(ALL:ALL) ALL
 gitlab-runner ALL=(ALL) NOPASSWD: ALL 

Output:

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
gitlab-runner ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
gitlab-runner ALL=(ALL) NOPASSWD: ALL

Step #4: Register GitLab Runner to GitLab on Ubuntu

1. First login to GitLab Server with Username and Password.

login to gitlab server with username and password

2. Click on your project and select Settings

goto gitlab project settings

3. Navigate to Settings and click on CI/CD inside this click on Expand of Runners section

goto gitlab CICD and expand

4. Copy GitLab server URL and Registration Token as shown below.

copy the gitlab server url and token

5. Paste GitLab Server URL and Token in registration command as below

$ gitlab-runner register --name project-name-runner --url https://gitlab.fosstechnix.com --registration-token  Uc7yzxTMzsXhXJx3zgM

OR

sudo gitlab-runner register

OR

if you want to register gitlab-runner with docker executor then use below command

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

6. Copy above command. Login to GitLab runner server through SSH and paste & run copied command on command line.

Follow the default options until which agent you need to register and then select agent as shown below

register gitlab runner using ssh

7. Once you registered Runner for project then you will get runner as below,

gitlab runner activated

Successfully, We have performed GitLab Runner Registration.

Error: This job is stuck because the project doesn’t have any runners online assigned to it. Go to Runners page.

Solution:

You have added tags while registering GitLab Runner however you have not added tags for your Job.

Follow below steps to add tags.

1. Navigate to Settings and click on CI/CD inside this click on Expand of Runners section

2. Go to Runners and check on Indicates whether this runner can pick jobs without tags Box

How to Install GitLab Runner on Ubuntu 20.04 LTS 1

Uninstall GitLab Runner from Ubuntu

First remove the gitlab-runner using apt

sudo apt purge --autoremove -y gitlab-runner

Remove the gitlab-runner apt key

sudo apt-key del 51312F3F

Remove gitlab-runner apt repository

sudo rm -rf /etc/apt/sources.list.d/runner_gitlab-runner.list

Remove the gitlab-runner user and directory

sudo deluser --remove-home gitlab-runner

Remove gitlab-runner installation directory

sudo rm -rf /etc/gitlab-runner

Conclusion

In this article, How to Install GitLab Runner on Ubuntu 20.04 and Register GitLab Runner to GitLab on Ubuntu.

Related Articles

How to Install GitLab on Ubuntu 18.04/16.04 LTS

Angular CI CD Pipeline with GitLab in 6 Easy Steps

Reference

GitLab Official Documentation

Shweta Mamidwar

I am Shweta Mamidwar working as a Intern in Product Company. Likes to share knowledge.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap