49  GitLab CI Runner 101

49.1 Install self-managed runners

Important
curl -LJO "https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_amd64.deb"
sudo dpkg -i gitlab-runner_amd64.deb

49.2 Configure self-managed runners

Is preferable to have non-root runners.

Create the configuration file ~/.gitlab-runner/config.toml and add

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

Create /etc/systemd/system/gitlab-runner-username.service and add

[Unit]
Description=GitLab Runner as username
After=syslog.target network.target
ConditionFileIsExecutable=/usr/local/bin/gitlab-runner

[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/usr/local/bin/gitlab-runner "run" "--working-directory" "/home/username" "--config" "/home/username/.gitlab-runner/config.toml" "--service" "gitlab-runner-username" "--syslog" "--user" "username"

Restart=always
RestartSec=120

[Install]
WantedBy=multi-user.target

Start the daemon:

sudo systemctl start gitlab-runner-username
sudo systemctl enable gitlab-runner-username
Important

On Debian and Ubuntu, the file default /home/username/.bash_logout makes the runner to not clone the Git repository as explained in https://forum.gitlab.com/t/gitlab-runner-as-non-root-does-not-clone-repo/21935/6.

49.3 Get status

sudo gitlab-runner status

49.4 List runners

gitlab-runner list

49.5 Create runner

gitlab-runner register

49.6 Remove runner

gitlab-runner unregister --name runner_name

49.7 Remove all runners

gitlab-runner verify --delete
gitlab-runner unregister --all-runners

49.8 Troubleshooting

Add

variables:
  CI_DEBUG_TRACE: "true"

to the job that is failing.