一、背景
在gitlab中新建了一个项目,添加了.gitlab-ci.yml文件,并在文件中写入了测试脚本内容:
stages: - deploy deploy: stage: deploy script: - ping -c 20 127.0.0.1
提交后,stage处于stuck状态,无法运行,检查执行者runner服务,runner服务也存在。
二、分析
考虑是该项目和.gitlab-ci.yml文件脚本的执行者runner之间,还没有建立联系。查询网上资料后,发现需要注册runner。
注册runner参考
https://www.jianshu.com/p/82db7ee85e86
https://blog.csdn.net/u011350541/article/details/80392694
三、方法
1、检查是否有runner服务,并且是否运行。
gitlab-runner status
2、注册runner和项目之间的联系
(1)注册runner前的准备,查询相关url和token
进入项目
projects-》settings-》CI/CD-》Runners (expand) -》Setup a specific Runner manually (记录 url 和 token的值)如下图所示:
(2)命令行注册runner
gitlab-ci-multi-runner register
以下内容的解释:
#引导会让你输入gitlab的url,输入自己的url,例如http://gitlab.example.com/ #引导会让你输入token,去相应的项目下找到token,例如ase12c235qazd32 #引导会让你输入tag,一个项目可能有多个runner,是根据tag来区别runner的,输入若干个就好了,比如web,hook,deploy #引导会让你输入executor,这个是要用什么方式来执行脚本,图方便输入shell就好了。
[root@localhost ~]# gitlab-ci-multi-runner register Running in system-mode. Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): http://10.1.2.3:8881/ Please enter the gitlab-ci token for this runner: 5mJH3e3zj_365voC5oLf Please enter the gitlab-ci description for this runner: [localhost.localdomain]: pro01_runner Please enter the gitlab-ci tags for this runner (comma separated): test01,pro01 Whether to run untagged builds [true/false]: [false]: true Whether to lock Runner to current project [true/false]: [false]: false Registering runner... succeeded runner=5mJHse3z Please enter the executor: docker, docker-ssh, parallels, shell, virtualbox, ssh, docker+machine, docker-ssh+machine, kubernetes: shell Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! [root@localhost ~]# gitlab-runner list Listing configured runners ConfigFile=/etc/gitlab-runner/config.toml pro01_runner Executor=shell Token=ccc9f3cb9609d7c52e5a84e8c51fa2 URL=http://10.1.2.3:8881/
(3)在gitlab的web界面可以看到
进入项目
projects-》settings-》CI/CD-》Runners (expand) -》Runners activated for this project 如下图所示:
3、查看脚本的运行
(1)脚本运行时的状态
projects-》CI/CD-》Pipelines -》stages -》 向下箭头 -》 刷新图标(Retry)
(2)脚本运行后的状态