安装gitlab-runner
需要在你的打包机器上安装gitlab-runner,在不同的平台上,安装gitlab-runner的方式不一致,可以参考官方文档:<u data-renderer-mark="true">https://docs.gitlab.com/runner/install/</u>这里以mac为例
# 下载文件(intel / apple)
#For Intel-based systems:
sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64
#For Apple Silicon-based systems:
sudo curl --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-arm64"
# 配置权限
sudo chmod +x /usr/local/bin/gitlab-runner
# 启动gitlab runner
gitlab-runner install
gitlab-runner start
如果遇到下述错误,请尝试手动创建bin文件夹
Warning: Failed to create the file /usr/local/bin/gitlab-runner: No such file or directory
注册gitlab-runner
[root@app3 ~]# sudo gitlab-runner register
Runtime platform arch=amd64 os=linux pid=6324 revision=1b659122 version=12.8.0
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://XXXX
Please enter the gitlab-ci token for this runner:
xxxxxxxx
Please enter the gitlab-ci description for this runner:
[app3]: test
Please enter the gitlab-ci tags for this runner (comma separated):
test
Registering runner... succeeded runner=rbLy6bws
Please enter the executor: parallels, docker-ssh+machine, custom, docker-ssh, shell, ssh, virtualbox, docker+machine, kubernetes, docker:
shell
Please enter the default Docker image (e.g. ruby:2.6):
jangrewe/gitlab-ci-android
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
执行上面的命令,就能将gitlab-runner注册到gitlab中,需要说明下执行命令时输入的几个参数,其中gitlab-ci coordinator URL和gitlab-ci token可以从项目(Group需要master权限)的Settings—>CI/CD—>Runners中查看,如下图所示:
image.pnggitlab-ci description是对runner的描述,根据情况填写即可。
gitlab-ci tags 是runner的标签,在后面的配置文件中会用到。
enter the executor是配置runner使用的执行器,可以是shell,如果你需要执行shell脚本的话。我们这里使用的是docker,使用了一个包含Android环境的容器:jangrewe/gitlab-ci-android。
另外,需要注意,在gitlab所在服务器的/etc/gitlab-runner/config.toml配置文件中也可以对gitlab-runner的注册信息进行修改。
启动gitlab-runner
需要注意的是,往gitlab注册一个新的runner之后,需要将gitlab-runner进行重启,这样,注册的runner才能生效。我在操作的时候,因为没有重启,花了好多时间解决出现的问题。其实只要重启即可解决。
#重启gitlab-runner
gitlab-runner restart
#执行gitlab-runner run
sudo gitlab-runner run
image.png
如果没有加速度将会出现上图所示提示,也是导致runner与gitlab链接不上的另一原因
检查gitlab-runner的状态
配置好之后,可以在项目的settings—>CI/CD中查看新增的runner是否是running状态,如下图所示:
image.png
网友评论