注册一个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

3.2 Runner 注册 - 图1

//使用主机方式注册

  1. $ gitlab-runner register
  2. Runtime platform arch=amd64 os=linux pid=23268 revision=c553af1a version=12.10.0
  3. Running in system-mode.
  4. Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
  5. https://gitlabtest.xiodi.cn
  6. Please enter the gitlab-ci token for this runner:
  7. zsy4iJK4-hPh8KctpVkM
  8. Please enter the gitlab-ci description for this runner:
  9. [c720133.xiodi.cn]:
  10. Please enter the gitlab-ci tags for this runner (comma separated):
  11. host20133,host-shell
  12. Registering runner... succeeded runner=zsy4iJK4
  13. Please enter the executor: virtualbox, docker+machine, docker-ssh, docker, parallels, shell, ssh, docker-ssh+machine, kubernetes, custom:
  14. shell
  15. Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

//注册之后显示如下
3.2 Runner 注册 - 图2

(2)注册一个组 Runner

群组 -> 设置 -> CI/CD -> Runner

3.2 Runner 注册 - 图3

//使用 docker 方式注册

  1. $ docker ps -a //前面已启动
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. dfa0f083e588 harbor.xiodi.cn/tools/gitlab-runner:v12.10.0 "/usr/bin/dumb-init …" 35 hours ago Up 35 hours gitlab-runner
  4. $ docker exec -it gitlab-runner /bin/bash
  5. root@dfa0f083e588:/# gitlab-runner register
  6. Runtime platform arch=amd64 os=linux pid=32 revision=c553af1a version=12.10.0
  7. Running in system-mode.
  8. Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
  9. https://gitlabtest.xiodi.cn
  10. Please enter the gitlab-ci token for this runner:
  11. Zz6yDBiRYLzdEBaHZLUm
  12. Please enter the gitlab-ci description for this runner:
  13. [dfa0f083e588]: host20133-docker-gitlab-runner
  14. Please enter the gitlab-ci tags for this runner (comma separated):
  15. group-host20133-docker,docker
  16. Registering runner... succeeded runner=Zz6yDBiR
  17. Please enter the executor: shell, ssh, virtualbox, docker-ssh+machine, docker+machine, kubernetes, custom, docker, docker-ssh, parallels:
  18. docker
  19. Please enter the default Docker image (e.g. ruby:2.6):
  20. Please enter the default Docker image (e.g. ruby:2.6):
  21. harbor.xiodi.cn/tools/alpine:3.11
  22. Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

//注册之后,gitlab 显示如下:

3.2 Runner 注册 - 图4

(3)注册一个组 项目 Runner

项目页面 -> 设置 -> CI/CD -> Runner

3.2 Runner 注册 - 图5

//这一次,我们使用一行注册命令

  1. $ docker run -d --name gitlab-runner2 --restart always \
  2. -v /data/etc/gitlab-runner2:/etc/gitlab-runner \
  3. -v /var/run/docker.sock:/var/run/docker.sock \
  4. harbor.xiodi.cn/tools/gitlab-runner:v12.10.0
  5. $ docker exec gitlab-runner2 gitlab-runner register \
  6. --non-interactive \
  7. --url "https://gitlabtest.xiodi.cn/" \
  8. --registration-token "jVrrMh1mwZtfzMH8Gv_X" \
  9. --executor "docker" \
  10. --docker-image harbor.xiodi.cn/tools/alpine:3.11 \
  11. --description "host20133-docker" \
  12. --tag-list "docker,host20133-docker" \
  13. --run-untagged="true" \
  14. --locked="false" \
  15. --access-level="not_protected"

//注册之后,GitLab 显示如下:

3.2 Runner 注册 - 图6

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