這里列出使用過程中遇到的問題,并嘗試給出解決方案集灌。
前言
關注持續(xù)集成晚凿、持續(xù)部署很久亭罪,看到Gitlab9社區(qū)版本功越來越完善,所以現(xiàn)在虛擬機是上手一下歼秽,玩熟練了推薦給公司的開發(fā)小組应役。
交代一下測試環(huán)境:
- gitlab版本 9.0.0
- gitlab-runner版本9.0.0
- OS:CentOS 7
- 項目:maven下的springboot樣例程序
- jdk8
在注冊runner的時候輸入的tag有什么用?
下面是注冊runner的交互過程燥筷,在操作過程中我對tag的輸入一直沒理解(問題就出在這里)箩祥。
[root@localhost ~]# gitlab-ci-multi-runner register
Running in system-mode.
## gitlab服務器的域名或IP+/ci
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://192.168.92.128/ci
## runnerToken,gitlab服務器上獲取
Please enter the gitlab-ci token for this runner:
3kjzGzK4PZDA73HYPHrP
## 描述
Please enter the gitlab-ci description for this runner:
[localhost.localdomain]: jdk8·test
##下面的tag輸入之后到底有什么用肆氓?袍祖?
Please enter the gitlab-ci tags for this runner (comma separated):
js
Registering runner... succeeded runner=3kjzGzK4
## 執(zhí)行容器,我用的shell
Please enter the executor: virtualbox, docker-ssh+machine, docker, docker-ssh, parallels, shell, ssh, docker+machine, kubernetes:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
當我注冊完runner谢揪,滿心歡喜推送了一個帶有.gitlab-ci.yml
文件的項目上去后蕉陋,我發(fā)現(xiàn)流水線一直是pending
狀態(tài)捐凭,查看job的提示顯示作業(yè)被卡住。請檢查runner凳鬓、**此作業(yè)被卡住茁肠,因為沒有任何活動的 runner 能運行此構(gòu)建。 **這樣的字樣缩举。明明runner注冊成功了垦梆,在排除了共享runner、獨自runner的問題之后蚁孔,我看到了官方.gitlab-ci.yml
文件中的介紹點擊查看官方介紹:tags奶赔,
摘入官方資料
tags
is used to select specific Runners from the list of all Runners that are allowed to run this project.
During the registration of a Runner, you can specify the Runner's tags, for example ruby, postgres, development
.
tags
allow you to run jobs with Runners that have the specified tags assigned to them:
job:
tags:
- ruby
- postgres
The specification above, will make sure that job is built by a Runner that has both ruby AND postgres tags defined.
所以惋嚎,當我把.gitlab-ci.yml
文件中加入tags
標示之后杠氢,項目可以順利的running了。
除此方式外另伍,還可以在runner注冊時候?qū)unner選為可以運行沒有任何標簽的作業(yè) 這一項鼻百。同樣可以解決問題,只不過這種方式在托管的代碼環(huán)境復雜的時候就不能隨性的設置多種runner環(huán)境了摆尝。
2. 基于maven的Runner環(huán)境怎么配置温艇?
基于SpringBoot的樣例工程,需要用到maven構(gòu)建堕汞,先看.gitlab-ci.yml
的代碼
build:
script:
- 'pwd && mvn test'
tags:
- java
這里就是執(zhí)行以下mvn test
,因為tags
標示的是java
勺爱,結(jié)合文章上面一個問題,這里需要使用打了標簽為java
的runner進行構(gòu)建讯检。
而我遇到的問題是琐鲁,maven 中的setting.xml
文件應該放在哪里?
setting.xml文件有位置的優(yōu)先級,從低到高依次:基于項目的pom.xml->user文件加下.m2/setting.xml->maven安裝目錄/conf/setting.xml人灼。
之前我將配置文件放在了root用戶的~/.m2/setting.xml,結(jié)果Runner執(zhí)行的時候并沒有讀取到我的配置围段,我猜gitlab-runner執(zhí)行時使用的是gitlab-runner用戶,因此直接修改maven安裝目錄/conf/setting.xml投放,保存再次執(zhí)行奈泪,搞定。