注册一个Runner是将Runner与GitLab实例绑定的过程。
1. 请求
在登记Runner之前,你需要先:
- 将它安装在与GitLab安装位置不同的服务器上
- 通过GitLab的接口获取共享或特定 Runner 的令牌
2. 注册
GitLab Runner 注册的方式有以下几种方式:
- 全局:只能注册共享Runnner,该 GitLab 实例中所有的项目都可使用该 Runner
群组:只能注册群组 Runnner,属于该组名称空间下的所有项目都可使用该 Runner
- 手动设置 Runner
- 利用 kubernetes 设置自动 Runner
特定 runner:只能注册属于该项目的特定 Runner。但可继承全局的共享 Runner 和群组的 Runner
- 手动设置 Runner
- 利用 kubernetes 设置自动 Runner
(1)注册一个全局 Runner
管理中心 -> 概览 -> Runner

//使用主机方式注册
$ gitlab-runner registerRuntime platform arch=amd64 os=linux pid=23268 revision=c553af1a version=12.10.0Running in system-mode.Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):https://gitlabtest.xiodi.cnPlease enter the gitlab-ci token for this runner:zsy4iJK4-hPh8KctpVkMPlease enter the gitlab-ci description for this runner:[c720133.xiodi.cn]:Please enter the gitlab-ci tags for this runner (comma separated):host20133,host-shellRegistering runner... succeeded runner=zsy4iJK4Please enter the executor: virtualbox, docker+machine, docker-ssh, docker, parallels, shell, ssh, docker-ssh+machine, kubernetes, custom:shellRunner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
//注册之后显示如下

(2)注册一个组 Runner
群组 -> 设置 -> CI/CD -> Runner

//使用 docker 方式注册
$ docker ps -a //前面已启动CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESdfa0f083e588 harbor.xiodi.cn/tools/gitlab-runner:v12.10.0 "/usr/bin/dumb-init …" 35 hours ago Up 35 hours gitlab-runner$ docker exec -it gitlab-runner /bin/bashroot@dfa0f083e588:/# gitlab-runner registerRuntime platform arch=amd64 os=linux pid=32 revision=c553af1a version=12.10.0Running in system-mode.Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):https://gitlabtest.xiodi.cnPlease enter the gitlab-ci token for this runner:Zz6yDBiRYLzdEBaHZLUmPlease enter the gitlab-ci description for this runner:[dfa0f083e588]: host20133-docker-gitlab-runnerPlease enter the gitlab-ci tags for this runner (comma separated):group-host20133-docker,dockerRegistering runner... succeeded runner=Zz6yDBiRPlease enter the executor: shell, ssh, virtualbox, docker-ssh+machine, docker+machine, kubernetes, custom, docker, docker-ssh, parallels:dockerPlease enter the default Docker image (e.g. ruby:2.6):Please enter the default Docker image (e.g. ruby:2.6):harbor.xiodi.cn/tools/alpine:3.11Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
//注册之后,gitlab 显示如下:

(3)注册一个组 项目 Runner
项目页面 -> 设置 -> CI/CD -> Runner

//这一次,我们使用一行注册命令
$ docker run -d --name gitlab-runner2 --restart always \-v /data/etc/gitlab-runner2:/etc/gitlab-runner \-v /var/run/docker.sock:/var/run/docker.sock \harbor.xiodi.cn/tools/gitlab-runner:v12.10.0$ docker exec gitlab-runner2 gitlab-runner register \--non-interactive \--url "https://gitlabtest.xiodi.cn/" \--registration-token "jVrrMh1mwZtfzMH8Gv_X" \--executor "docker" \--docker-image harbor.xiodi.cn/tools/alpine:3.11 \--description "host20133-docker" \--tag-list "docker,host20133-docker" \--run-untagged="true" \--locked="false" \--access-level="not_protected"
//注册之后,GitLab 显示如下:

[info]此号码,是该GitLab 实例中第几次注册 Runner,即使注册完成后,删除,该号码也不可再用,会继续往下使用。
