说明
gitlab配置CI/CD流水线,基于gitlab版本15.11
先以最简单的配置运行起来,分解难度,跑通了再深入学习实践
安装启动runner
安装参考https://www.tang.show/docker/runner/
#直接在centos7系统安装,选shell类型,降低困难度
检查gitlab项目页面地址
对于自己部署的runner如果地址不是ip或域名,需要设置下否则cicd无法拉代码
设置成ip参考https://www.tang.show/git-gitlab/docker%e5%ae%89%e8%a3%85gitlab/
中的初始化配置>>设置url地址|设置gitlab克隆地址
然后执行gitlab-ctl reconfigure 和gitlab-ctl restart #重载、重启

注册runner
可在gitlab页面http://192.168.2.32/admin/runners页面获取token信息或复制快捷命令
然后在安装runner的机器上执行:
gitlab-runner register --url http://192.168.2.32/ --registration-token xxxzCZHvrsa Runtime platform arch=amd64 os=linux pid=38319 revision=436955cb version=15.11.0 xx
Enter the GitLab instance URL (for example, https://gitlab.com/):#回车
[http://192.168.2.32/]:
Enter the registration token:#回车
[3HjVKq225ryLzCZHvrsa]:
Enter a description for the runner:
[localhost]:
Enter tags for the runner (comma-separated):#回车,设置为默认,这样yaml文件不用指定就能调用该runner
Enter optional maintenance note for the runner:
WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with xx
Registering runner... succeeded runner=3HjVKq22
Enter an executor: ssh, virtualbox, docker-autoscaler, custom, docker, docker-windows, docker-sshx xx -ssh+machine:#直接输入shell,再回车
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
#注册完成,gitlab页面查看,runner已上线
新建项目
创建一个项目,在根目录放置.gitlab-ci.yml,内容如下:
pages:
stage: deploy
environment: production
script:
- echo "hello"
- mkdir .public
- cp -r ./* .public
- rm -rf public
- mv .public public
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
然后新一个任意文件,配置正确的会触发cicd流程按上配置执行
观察执行
如图,执行已完成:

登录runner执行 find / -name testabc,返回以下,代表已成功拉下项目,并且执行了yaml配置:
/home/gitlab-runner/builds/2jw2Jm3g/0/gitlab-instance-f0987d43/r1/testabc
/home/gitlab-runner/builds/2jw2Jm3g/0/gitlab-instance-f0987d43/r1/public/testabc、
在gitlab页面上也能查看执行的详情:
