gitlab-runner那些坑
最近部署gitlab-runner时候遇到了一些坑,随手记录下来
- 参考文献
gitlab之gitlab-ci自动部署
gitlab-ci配置
1.在本地安装runner
> curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash
> sudo apt-get update
> sudo apt-get install gitlab-ci-multi-runner
2.重置git-runner用户权限
- 一般设置为管理员权限,不然无法磁盘读写权限和系统使用权限;
> sudo gitlab-ci-multi-runner uninstall
> sudo gitlab-ci-multi-runner install -u (用户名)
3.注册一个可用的runner
> sudo gitlab-ci-multi-runner register
WARNING: Running in user-mode.
WARNING: The user-mode requires you to manually start builds processing:
WARNING: $ gitlab-runner run
WARNING: Use sudo for system-mode:
WARNING: $ sudo gitlab-runner...
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): # <font color=#FF0000>填写Gitlab服务器地址 </font>
例如http://gitlab.example.com/
Please enter the gitlab-ci token for this runner: # <font color=#FF0000>填写项目CI/CD中的令牌 </font>
d6jxxxxxxxxxxxxx
Please enter the gitlab-ci description for this runner: # <font color=#FF0000>填写runner名称</font>
runner_xxx
Please enter the gitlab-ci tags for this runner (comma separated): # <font color=#FF0000>填写Runner的标签,用于和服务器进行匹配,和填多个,用","分割</font>
release #标签用于后面分支运行时候使用的runner
Whether to run untagged builds [true/false]: # <font color=#FF0000>是否允许无标签运行,默认false,建议不做修改 </font>
[false]:
Whether to lock Runner to current project [true/false]: # <font color=#FF0000>在运行时是否锁定项目,建议填true </font>
[false]: true
Registering runner... succeeded runner=d6jAc4iw
Please enter the executor: virtualbox, docker-ssh+machine, kubernetes, docker-ssh, ssh, shell, docker+machine, docker, parallels: # <font color=#FF0000>填写Runner的执行方式 </font>
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
查看git-runner状态和信息
> sudo gitlab-ci-multi-runner list #获取Runner列表
Listing configured runners ConfigFile=/etc/gitlab-runner/config.toml # 配置文件路径
runner_xxx Executor=shell Token=hx9xyRsYxxxxxxURL=http:XXXXXXX
> sudo gitlab-ci-multi-runner status #获取Service运行状态
gitlab-runner: Service is running.
> sudo gedit /etc/systemd/system/gitlab-runner.service
... "--working-directory" "/media/lxx/SSD2T/work_idh/git_runner" ...
> systemctl daemon-reload # 重启加载
> systemctl restart gitlab-runner # 重启服务
仓库配置文件.gitlab-ci.yml
- 在本地仓库的根目录下创建,项目git push时候就会触发
- 在code根目录中,创建.gitlab-ci.yml文件
stages:
- build #构建一个项目
build:
stage: build
only: #仅仅在此分支触发
- xxxxx #分支名字
script:
- make all #运行脚本
tags:
- release #runner的标签
问题
Job’s log exceeded limit of 4194304 bytes.
- 出现该问题主要是因为gitlab runner默认日志大小为4096,修改相关配置即可
> sudo gedit /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
[[runners]]
name = "ci"
url = "http://git.***.org/"
token = "6f2xxxxxxxxxxxx"
executor = "shell"
builds_dir = "/mdata/builds"
# 此行为新增行,默认配置为4096
output_limit = 81920
[runners.cache]
> sudo gitlab-ci-multi-runner restart #重启gitlab runner
- runner灰色下线无法找到runner标签,重启runner
> sudo gitlab-runner restart
- runner一直等待中,一般是找不到可以使用匹配得上的runner
-
解决
1移除runner
2.重置令牌
3.删除/etc/gitlab-runner/config.toml配置
也可以查看下home目录下有没有该配置,有的话也可以删除> gedit ~/.gitlab-runner/config.toml
> sudo rm /etc/gitlab-runner/config.toml
4.重新注册一个runner即可
> sudo gitlab-ci-multi-runner register