注册Runner
1.运行一下命令:
gitlab-runner register
2.输入我们的GitLab实例URL
http://repo.ehailiang.com:8088/
3.输入GitLab项目仓库的令牌以注册Runner
4.输入Runner描述
5.输入与该Runner关联的标签 (此步千万不要乱输入,它是和项目的.gitlab.ci.yml 相对应的)
6.输入Runner执行程序 (我们选择使用docker来进行)
7.如果选择了docker作为执行程序,则需要输入一个默认执行的镜像 (此镜像为已经提前做好的扫描代码规范的镜像)
GItLab CI
当注册了GitLab Runner之后,如何在项目中具体应用呢?
.gitlab-ci.yml 详细介绍:http://repo.ehailiang.com:8088/help/ci/yaml/README.md
在项目根目录下创建 .gitlab-ci.yml文件
stages:
- phpcs
- phpstan
job1:
stage: phpcs
image: registry.cn-hangzhou.aliyuncs.com/iclass/phpscan:latest
tags:
- phpcs
only:
- develop
allow_failure:
true
script:
- source /etc/profile
- phpcs --standard=PSR2 --encoding=utf-8 -n -p /builds/iclass/iuser/modules/
job2:
stage: phpstan
image: registry.cn-hangzhou.aliyuncs.com/iclass/phpscan:latest
tags:
- phpstan
only:
- develop
allow_failure:
true
script:
- source /etc/profile
- phpstan analyse --level=1 --no-progress --autoload-file=/builds/iclass/iuser/phpstan.php /builds/iclass/iuser/modules/
具体过程描述:
GitLab Runner 以镜像
registry.cn-hangzhou.aliyuncs.com/iclass/phpscan:latest
创建一个内部容器,checkout项目的 develop分支出来 进行 script 配置的脚本运行在容器内运行,从而扫描我们项目的代码规范。