简介
GitLab Runner是一个开源项目,用于运行作业并将结果发送回GitLab,GitLab Runner类似Jenkins的agent,执行CI持续集成构建的脚本任务。
GitLab Runner类型与状态
类型
- shared共享类型,运行整个平台项目的作业(gitlab)
- group项目组类型,运行特定group下的所有项目的作业(group)
- specific 项目类型,运行指定的项目作业(project)
状态
- locked: 锁定状态,无法运行项目作业
- paused: 暂停状态,暂时不会接受新的作业
查看GitLab版本
安装Runner时候要注意与GitLab保持一致,避免版本不一致导致的差异化
安装GitLab Runner的两种方式
方式一: 使用二进制方式安装GitLab Runner
# 下载平台对应的安装包
wget https://gitlab-runner-downloads.s3.amazonaws.com/latest/rpm/gitlab-runner_amd64.rpm
# 安装下载好的二进制安装包
rpm -ivh gitlab-runner_amd64.rpm
注册runner
注册步骤
获取token -> 进行注册
GitLab Runner类型
- shared: 运行整个平台项目的作业(gitlab)
- group:运行特定group下的所有项目的作业(group)
- specific: 运行指定的项目作业(project)
- locked: 无法运行项目作业
- paused: 不会运行作业
获取shared类型的token
运行注册命令
gitlab-runner register
# 运行上面的命令后会有很多选项,依次填入即可
Please enter the gitlab-ci coordinator URL:输入 ci 地址
Please enter the gitlab-ci token for this runner:输入 ci token
Please enter the gitlab-ci description for this runner:输入 runner 名称
Please enter the gitlab-ci tags for this runner:设置 tag
Whether to run untagged builds:这里选择 true ,代码上传后会能够直接执行
Whether to lock Runner to current project:直接回车,不用输入任何口令
Please enter the executor:选择 runner 类型,这里我们选择的是 shell
注册完后可以在gitlab看到该runner
获取group类型的token
进入到组里面查看
获取项目类型Runner的token
方式二: 使用Docker运行GitLab runner 容器
运行Runner容器
docker run --name gitlab-runner --restart always -d -v /var/run/docker.sock:/var/run/docker.sock -v /gitlab-runner/config/:/etc/gitlab-runner gitlab/gitlab-runner:latest
进入容器,进行注册
[root@node1 ~]# docker exec -it gitlab-runner bash
root@685ba366ac28:/# gitlab-runner register \
--non-interactive \
--executor "docker" \
--docker-image "golang" \
--url "http://192.168.0.184" \
--registration-token "5BNky7RgKXxrj_aNjyzu" \
--description "golang build runner" \
--tag-list "golang" \
--run-untaged="true"
Gitlab Runner的一些常用命令
[root@node1 ~]# gitlab-runner list
Runtime platform arch=amd64 os=linux pid=163944 revision=8ec04662 version=16.3.0
Listing configured runners ConfigFile=/etc/gitlab-runner/config.toml
deploy Executor=shell Token=RwDXwMy7F6pwTdpbwTFC URL=http://192.168.0.184
[root@node1 ~]# gitlab-runner verify
Runtime platform arch=amd64 os=linux pid=164572 revision=8ec04662 version=16.3.0
Running in system-mode.
Verifying runner... is alive runner=RwDXwMy7