gitlab項目關聯runner


一、背景

在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)腳本運行后的狀態

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM