GitLab Runner

Page content

Pre-requirement

I installed Docker because I wanted to use Docker executor for better isolation of environments.

Install GitLab Runner on the server

Follow the official manual.

https://docs.gitlab.com/runner/install/linux-repository.html

  • On Ubuntu
  • From repo (recommended)
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
export GITLAB_RUNNER_DISABLE_SKEL=true; sudo -E apt install gitlab-runner

Check.

$ sudo gitlab-runner status
Runtime platform                                    arch=amd64 os=linux pid=3163 revision=2ebc4dc4 version=13.9.0
gitlab-runner: Service is running!

$ sudo gitlab-runner list
Runtime platform                                    arch=amd64 os=linux pid=3172 revision=2ebc4dc4 version=13.9.0
Listing configured runners                          ConfigFile=/etc/gitlab-runner/config.toml

Register for your GitLab

https://docs.gitlab.com/runner/register/

I registred the Runner as a shared.

Get a registration token

  1. Create a project. I created as “Internal”.
  2. Settings -> CI/CD, expanding the Runners section.
  3. Check the registration token at “Set up a specific runner manually -> 2”
  4. In the Runner instance, run the gitlab-runner register.
# gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=4429 revision=2ebc4dc4 version=13.9.0
Running in system-mode.

Enter the GitLab instance URL (for example, https://gitlab.com/):
https://{{ your_GitLab_hostname }}
Enter the registration token:
{{ the_token_you_get }}
Enter a description for the runner:
[{{ your_GitLab_Runner_hostname }}]: 
Enter tags for the runner (comma-separated):
docker,ansible
Registering runner... succeeded                     runner=********
Enter an executor: docker, docker-ssh, shell, ssh, virtualbox, docker+machine, docker-ssh+machine, kubernetes, custom, parallels:
docker
Enter the default Docker image (for example, ruby:2.6):
alpine:3.13
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

To register the Runner send a POST request to https://{{ your_GitLab_hostname }}/api/v4/runners.

Tips: For self-signed certificate (https)

https://docs.gitlab.com/runner/configuration/tls-self-signed.html#supported-options-for-self-signed-certificates

  1. Get your self-signed certificate.
  2. Create /etc/gitlab-runner/certs/{{ hostname }}.crt.
  3. Paste the certificate to the created file.

And, retry the registration.

Problem: apt install Runner permission (memo)

gitlab-runner stop
gitlab-runner uninstall
gitlab-runner install --user=atlex00 --working-directory=/home/atlex00
gitlab-runner start

Smarter method (need to check)

--config /etc/gitlab-runner/config.toml

Troubleshooting: shell executor

  • “Shell executor” runner runs scripts directly with ssh.
  • The working directory is home directory of the user gitlab-runner (as default), or working-directory option in config file. Check also ps aux | grep gitlab.
  • If you run Docker on a shell executor runner (don’t do that. use docker executor), be careful about mount points. Your CI pipeline could contain a test stage. In this case, temporary log files should be deleted at the end of the pipeline, otherwise it can lead to permission matter.