Gitlab runner
一、安装:
-
通过yum安装于本机
(1) 添加yum源
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash
(2) 安装
yum install gitlab-ci-multi-runner
(3) 注册
- 通过gitlab获取GitLab-CI的url和注册token
- 运行
gitlab-ci-multi-runner register
开始注册
-
通过docker安装部署
(1)拉取镜像
docker pull gitlab-runner
(2)启动镜像
docker run -d --name runnertest-builder --restart always -v /etc/gitlab-runner:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
(3)配置runner
docker exec -it runnertest-builder gitlab-runner register
二、使用:
- .gitlab-ci.yml
三、遇到的问题:
报错:
fatal: unable to access 'http://gitlab-ci-token:xxxxxx@ip/xxx/citest.git': Failed to connect to xx.xx.xx.xxx port 80: Connection refused
报错:
Reinitialized existing Git repository in /data/builds/0ea06a67/0/。。。backend/.git/
Fetching changes with git depth set to 10...
fatal: git fetch-pack: expected shallow list
fatal: The remote end hung up unexpectedly
ERROR: Job failed: exit status 1
原因:
git版本低会导致用新的git特性不稳定。需要进行git版本升级
解决办法:
升级到与github匹配的版本
步骤如下:
删除旧版本git
yum remove git -y
安装3方yum 源,centos7 基础仓库,提供的 git 版本只有到 1.8.3,沒办法使用 git 2 的一些新功能
yum install https://centos7.iuscommunity.org/ius-release.rpm
安装新版本git
yum install git2u -y
验证版本
git --version
重新安装runner
yum install gitlab-runner -y
修改runner配置:
vi /etc/systemd/system/gitlab-runner.service
ExecStart=/usr/lib/gitlab-runner/gitlab-runner "run" "--working-directory" "/home/gitlab-runner" "--config" "/etc/gitlab-runner/config.toml" "--service" "gitlab-runner" "--syslog" "--user" "gitlab-runner"
改为:
ExecStart=/usr/lib/gitlab-runner/gitlab-runner "run" "--working-directory" "/home/gitlab-runner" "--config" "/etc/gitlab-runner/config.toml" "--service" "gitlab-runner" "--syslog" "--user" "root"
重新注册runner
gitlab-runner register
启动runner服务
systemctl daemon-reload
systemctl start gitlab-runner
即可
问题:
ERROR: Job failed: Error response from daemon: pull access denied for dotnet, repository does not exist or may require 'docker login' (executor_docker.go:188:8s)
问题原因:
这是由于以gitlab-runner用户登录,没有权限执行相关命令
解决方法:
将gitlab-runner添加为免密sudo用户
或将
/etc/systemd/system/gitlab-runner.service文件中的
ExecStart=/usr/lib/gitlab-runner/gitlab-runner "run" "--working-directory" "/home/gitlab-runner" "--config" "/etc/gitlab-runner/config.toml" "--service" "gitlab-runner" "--syslog" "--user" "gitlab-runner"
修改为:
ExecStart=/usr/lib/gitlab-runner/gitlab-runner "run" "--working-directory" "/home/gitlab-runner" "--config" "/etc/gitlab-runner/config.toml" "--service" "gitlab-runner" "--syslog" "--user" "root"
重新注册runner
gitlab-runner register
启动runner服务
systemctl daemon-reload
systemctl start gitlab-runner
即可
问题:
sudo: no tty present and no askpass program specified
ERROR: Job failed: exit status 1
问题原因:sudo之后需要输入密码,没输入超时就会提示这个。
解决办法:免密sudo或不用这个方法,可参考问题二