安装
install gitlab-runner on linux
centos 通过 yum install gitlab-runner 命令可以直接安装。
# 我的是 centos
第一步,执行:
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
第二步,执行
sudo yum install gitlab-runner
不知怎么终于安装成功了
Running with gitlab-runner 14.1.0 (8925d9a0)
on gitlab test GFWBHC1G
Preparing the "custom" executor
WARNING: custom executor is missing RunExec
ERROR: Job failed: custom executor is missing RunExec
下面是 gitlab runner 的工作流
yml 文件关键词
rules 关键词配置,精细化控制 docs.gitlab.com/ee/ci/jobs/…
整个 gitlab-ci 的工作流
www.digitalocean.com/community/t…
看不到仓库的 ci/cd 配置菜单
看这个文档 docs.gitlab.com/ee/ci/enabl…
打算在一个新的仓库里配置 ci/cd,添加了 .gitlab-ci.yml 文件,但是发现在仓库里没有找到 ci/cd 的菜单,看上面的文档。
依次打开 Settings/General/Visibility, project features, permissions,点击 expand,下拉可以看到 ci/cd 的开关,打开开关之后,下拉有个按钮 save changes,点击之后就可以看到了。
注册 gitlab-runner
运行 gitlab-runner
sudo gitlab-runner register --url https://<gitlab-host.com>/ --registration-token $REGISTRATION_TOKEN
这里的 $REGISTRATION_TOKEN 要从你自己的 gitlab 仓库中获取,左侧菜单 settings, ci/cd, runner
rsync 的时候报错
运行 gitlab-runner 的服务器把代码打包好之后会通过 rsync 的方式发给另外一台服务器,但是在 gitlab 的 pipeline 中显示如下错误:
Host key verification failed.
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.2]
之前一直以为是和 ssh key 相关,试了好多次。最后发现只需要在 gitlab-runner 的服务器上执行一次 ssh root@<另外一台服务器的ip>,然后会自动登录一次就好了。
参考 rsync-host-key-verification-failed
In my case I was able to just 'ssh user@host' first and it offered to auto-generate the key for me which was then saved for subsequent sessions.
安装 nodejs
在服务器上进行打包,需要安装 nodejs,之前一直执行命令 yum install node,后来发现少了 js 这两个字母。应该是 yum install nodejs。就可以了,然后 npm i -g n 来全局安装一个 n 的 nodejs 版本管理工具。可以切换 node 版本。
先安装 nvm,然后再安装对应的 nodejs 版本是更好的方式。直接执行如下命令就可以了:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash