This page looks best with JavaScript enabled

Configuring the GitLab CI Runner

 ·  ☕ 4 min read

1. Downloading and Configuring the Runner

1.1 Downloading the Runner

The GitLab CI Runner is a program package written in Go; you can download it from the official site to your local machine.

1
2
yum install -y wget
wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

Add execute permission

1
chmod +x /usr/local/bin/gitlab-runner

1.2 Adding a runner User

When running the Runner, run it under the runner:runner account.

1
2
groupadd -g 1234 runner
useradd runner -u 1234 -g 1234

1.3 Changing the pip Source

1
2
3
4
cat /etc/pip.conf
[global]
index-url= http://pypi.doubanio.com/simple/
trusted-host = pypi.doubanio.com

1.4 Creating the Working Directory

1
mkdir -p /data/gitlab-data

2 Registering the Runner

You can find the token on the project’s settings/ci_cd page, or on the administrator’s /admin/runners page.

The token is the credential for registering a Runner. If the token comes from a project, this Runner belongs to that project, and you can configure it to allow other projects to use it as well. If the token comes from the administrator page, this Runner is visible to and usable by all projects.

The following uses a project Runner as an example:

2.1 Getting the token

On the project’s settings/ci_cd page

You need to get the two parameters blurred out in the figure:

2.2 Registering the Runner

Run the command below and enter the relevant information as prompted.

1
/usr/local/bin/gitlab-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):

Enter the GitLab URL

1
http://gitlab.yourdomain.com/
Please enter the gitlab-ci token for this runner:

Enter the token

1
XXXXXXXXXXXXXXXXXXX
Please enter the gitlab-ci description for this runner:

Enter the Runner description

1
MyShellRunner
Please enter the gitlab-ci tags for this runner (comma separated):

Enter the Runner’s tags:

1
shell, linux
Whether to run untagged builds [true/false]:

Whether to run on builds that have no tag. When configuring gitlab-ci there will be many jobs, and each job can select a Runner via the tags attribute. Setting this to true here means that if a job has no tags configured, it will still run.

1
true
Whether to lock the Runner to current project [true/false]:

Whether to lock the Runner to the current project

1
false
Please enter the executor: parallels, ssh, virtualbox, docker-ssh+machine, kubernetes, docker, docker-ssh, shell, docker+machine:

Choose the executor; many executors are listed here

1
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

3 Running the Runner

1
/usr/bin/gitlab-runner run --working-directory /data/gitlab-data --config /etc/gitlab-runner/config.toml --service gitlab-runner --user runner >/dev/null 2>&1 &

Here, so as not to modify the yml configuration, we migrate from the previous Runner to the new Runner. We simply disable the shared Runner and use a Specific Runner. If you are willing to modify the yml, you can control which Runner executes via the tags parameter.

The rest is just configuring a suitable CI environment on the new Runner, such as node and npm.

Viewing the default startup configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
cat /etc/systemd/system/gitlab-runner.service

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

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

Restart=always
RestartSec=120

[Install]
WantedBy=multi-user.target

You can also manage the Runner via systemctl

1
systemctl restart gitlab-runner

4. Some Issues

4.1 Unregistering the Runner

You first need to find the token in the config.toml file; note that this token is different from the one used at registration.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
cat /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0

[[runners]]
  name = "myshell"
  url = "http://gitlab.yourdomain.com/"
  token = "XXXXXXXXXXxxxxxxxxxxxxx"
  executor = "shell"
  [runners.cache]
1
gitlab-runner unregister --url http://gitlab.yourdomain.com/ --token XXXXXXXXXXxxxxxxxxxxxxx

4.2 SVN Can’t convert string from ‘UTF-8’

Fixing the svn: Can’t convert string from ‘UTF-8’ to native encoding problem

1
2
locale
export LC_ALL=zh_CN.UTF-8

5. References


微信公众号
WRITTEN BY
微信公众号