持續集成之④:GitLab觸發jenkins構建項目


持續集成之④:GitLab觸發jenkins構建項目

一:目的為在公司的測試環境當中一旦開發向gitlab倉庫提交成功代碼,gitlab通知jenkins進行構建項目、代碼質量測試然后部署至測試環境,注意這只是測試環境,而生產環境依然需要手動部署代碼:

1.1:jenkins配置:
1.1.1:安裝Gitlab Hook Plugin插件:
#系統管理-管理插件-可選插件-Gitlab Hook Plugin和Build Authorization Token Root Plugin

1.1.2:生成隨機token:

# openssl rand -hex 12
0f2a47c861133916d2e299e3

 

1.1.3:創建項目觸發器:
#項目-配置-構建觸發器:
http://192.168.3.199:8080/jenkins/project/web-demo

1.2:配置github:
1.2.1:在git項目配置界面設置鏈接和token:

登錄gitlab,在這個項目下找到鈎子配置的地方


#選擇項目-設置-webhooks:
#插件使用介紹,https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin

http://192.168.3.199:8080/jenkins/buildByToken/build?job=web-demo&token=0f2a47c861133916d2e299e3
http://jenkins服務器地址:8080/buildByToken/build?job=項目名&token=token值

1.2.2:測試:

報錯:
hook executed successfully but returned http 404

本次是因為沒有在項目后面加上jenkins這個路徑

1.2.2:測試,看到顯示201表示成功

1.3:向git服務器提交代碼,驗證是否可以自動部署:
1.3.1:提交代碼:

[www@master code]$ git clone git@192.168.3.198:web/web-demo.git
[www@master web-demo]$ echo "Build token root plugin" > index.html 
[www@master web-demo]$ git add 'index.html'
[www@master web-demo]$ git commit -m 'build token root plugin test'
[master beb37cb] build token root plugin test
1 file changed, 1 insertion(+), 1 deletion(-)
[www@master web-demo]$ git push origin master
Counting objects: 5, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 281 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To git@192.168.3.198:web/web-demo.git
c02523b..beb37cb master -> master

1.3.2:jenkins服務器的日志記錄:

[root@node1 tomcat]# tail -f /usr/local/tomcat/logs/catalina.out

 

1.3.3:jenkins項目構建:

1.3.4:訪問web界面驗證代碼是否最新的:

1.3.5:jenkins控制台輸出信息:


免責聲明!

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



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