前進是:你已經配置好jenkins+gitlab自動化佈置了,這裏只是常規構建新的項目時,須要作的配置,記錄下來,以避免忘了又着急python
參考這篇博客:git
https://www.jianshu.com/p/eeb15a408d88shell
寫的很是棒~謝謝前輩服務器
Jenkins 和 GitLab 上建立測試工程。在 Jenkins Dashboard 主頁點擊 新建任務,進入新建任務頁面:gitlab
在工程配置頁面的 源碼管理部分,輸入 GitLab repo 的 URL,以下圖:測試
找到 構建觸發器 的部分,勾選 Build when a change is pushed to GitLab 那一行:ui
若是要測試jenkins和gitlab有沒有鏈接成功spa
點擊 Test 下拉框中的 Push events3d
點開特定調用的 View details,還能夠看到此次調用的詳細狀況,以下圖:blog
這就測試jenkins和gitlab鏈接成功了
接下來,如何使jenkins自動佈署gitlab已經存在的項目呢
首先,把gitlab上的項目克隆到服務器本地
先建立一個文件夾存放git項目
執行git命令:
[root@67 gitProject]# git clone git@git.5i5j.com:kaifa/reponselogiccheck.git
而後驗證項目能夠在服務器本地跑通
先看看項目裏的都有什麼文件
[root@67 gitProject]# cd reponselogiccheck/
[root@67 gitProject]# ls
咱們測試jenkins構建a.py文件(構建成功,控制檯會輸出Hello World)
[root@67 reponselogiccheck]# cat a.py
print("Hello World")
先來肯定python3可執行文件全部的目錄(配置jenkins構建job時要用)
[root@67 reponselogiccheck]# whereis python3
python3: /usr/bin/python3 /usr/local/python3
再打印出a.py的絕對路徑(第1個是我存放a.py文件的位置,第2個是什麼意思,如今我還說不上來,這是jenkins構建時,產生的目錄吧?)
(配置jenkins構建job時要用)
[root@67 reponselogiccheck]# find / -name a.py
/home/wangju/gitProject/reponselogiccheck/a.py
/root/.jenkins/workspace/testJenkins_gitlab/a.py
我先肯定腳本在shell命令下是能夠執行的
[root@67 local]# /usr/bin/python3 /home/wangju/gitProject/reponselogiccheck/a.py
Hello World
最後經過shell命令配置jenkins構建項目的地址
選擇已經配置好gitlab push代碼自動觸發jenkins構建的job
咱們試一下,修改a.py的內容,並將其push到gitlab上以後,jenkins是否是構建了最新的代碼的呢?
修改內容以下:
保存文件
將其push到gitlab上
先cd /home/wangju/gitProject/reponselogiccheck到本地倉庫目錄
執行
git add .
git status 查看是否是檢測到了更新
git commit -m "update a.py"
git status
將修改後的a.py推到gitlab
git push
push 成功了
接下來就是驗證jenkins有沒有輸出這句話了,好緊張,我如今不肯定我這樣的操做是否是對的
jenkins自動構建代碼了
輸出這句話了,yeah yeah yeah,good job well done~