gitlab与jenkins的自动化部署(通过webhook与ansible)
gitlab與jenkins的自動化部署(通過webhook與ansilble)
1、部署介紹
gitlab服務器:192.168.1.49:80
jenkins服務器:192.168.1.49:8180
ps:由于兩個服務運行在同一臺服務器上面,因此,為了保證jenkins服務器能拉取到 gitlab的代碼,把root的用戶的公鑰分別上傳到gitlab admin用戶跟jenkins admin用戶當中去。jenkins我沒有使用默認的端口8080,主要是我公司的gerrit架構會用到這個8080端口,所以為了防止沖突,改為8180端口
?
2、gitlab安裝?
a) 第一步:安裝相應的在依賴包(postfix或者sendmail),其中選擇internet site這種網絡smtp郵件服務器這種方式來發送郵件,其他一些依賴包:curl \openssh-server\ ca-certificates\ postfix
If you install Postfix to send email please select 'Internet Site' during setup. Instead of using Postfix you can also use Sendmail or configure a custom SMTP server . If you wish to use Exim, please configure it as an SMTP server.
On Centos 6 and 7, the commands below will also open HTTP and SSH access in the system firewall.
操作命令:
sudo apt-get install curl openssh-server ca-certificates postfix
b) 第二步:Add the GitLab package server and install the package. 下載gitlab安裝包,并且安裝
方法1、增加yum源鏈接,使用sduo apt-get install gitlab-ee
Apt-get安裝Curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh|sudo bash
操作命令:
sudo apt-get install gitlab-ce
If you are not comfortable installing the repository through a piped script, you can find the entire script here .
Alternatively you can select and download the package manually and install using
方法2、deb包安裝下載deb包,然后安裝
下載: sudo wget https://packages.gitlab.com/gitlab/gitlab-ee
安裝: sudo dpkg -i gitlab-ce_8.1.2-ee.0_amd64.deb
建議一般下載后再裝
c)第三步,啟用配置,并且啟動 GitLab
操作命令:
sudo gitlab-ctl reconfigure
d) 第四步:打開網頁,進行注冊,使用默認密碼
http://192.168.0.177:80
Username: rootPassword: 5iveL!fe
e) 第五步:2.1.6. Upload your license(EE版本需要認證,CE) 這步我操作的時候是沒有的
Go toAdmin > Licenseand upload your.gitlab-licensefile.
Don't have a license yet? Get a subscription.
其實只要下載到gitlab ce包(ce是社區版,不用驗證的),直接安裝就行了,啟動命令為gitlab-ctl reconfigure
?
3、jenkins安裝?
a) Install Jenkins
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
b) Starting Jenkins
nohup java -Dorg.jenkinsci.plugins.gitclient.Git.timeOut=60 -Dfile.encoding=UTF-8 -Dhudson.DNSMultiCast.disabled=true -jar /usr/share/jenkins/jenkins.war --httpPort=8180 > /var/log/jenkins_log 2>&1 &
(注意--httpPort=8180放在后面)
c) 開啟 jenkins頁面為:192.168.0.179:8180
http://xxxxx:8180/
d) 插件安裝
Git Plugin
SSH Plugin
URL Trigger Plugin
Gerrit Trigger Plugin
Gitlab Hook
Gitlab Merge Request Builder
GitLab Plugin
e) 注冊用戶
先開啟用戶注冊按鈕,用戶注冊完畢以后,關閉用戶注冊
?
4、配置jenkins拉取gitlab項目的賬號的sshkey
由于兩個服務運行在同一臺服務器上面,因此,為了保證jenkins服務器能拉取到 gitlab的代碼,把root的用戶的公鑰分別上傳到gitlab admin用戶跟jenkins admin用戶當中去。步驟我就不寫了!
?
?
5、配置jenkins項目
? 1、登錄192.168.1.49:8180
點擊新建:
?
依次填寫相關信息:(注意,項目安全這塊是在日常管理中才會用到,如果簡單測試可以忽略)
源碼管理:
?
觸發器:
我這里選擇得比較多,有push觸發,也有merge觸發
構建:(通過shell來構建)
我這里是通過簡單的ansible來控制web服務器的壓縮包scp,tar解壓,還有指定軟聯接
#變量WORKSPACE、GIT_URL是jenkins默認內置的變量
jenkins這邊就配置完了
但是注意:jenkins跟gitlab怎么通信觸發呢?
大家請留意觸發器那塊有一句話:
Build when a change is pushed to GitLab. GitLab CI Service URL: http://192.168.1.49:8180/project/launcher
它的意思的,gitlab ci接口可以通過http://192.168.1.49:8180/project/launcher來連接兩者的有關系。
?
6、gitlab設置webhook
在對應的gitlab項目設置當中,設置webhooks
當然,這里也可以設置triger事件:
保存后會在底部,生成webhook,點擊test,看jenkins界面是否觸發了!
登錄jenkins界面:192.168.1.49:8180
然后大功告成!
?
轉載于:https://www.cnblogs.com/to-be-rich/p/7655838.html
總結
以上是生活随笔為你收集整理的gitlab与jenkins的自动化部署(通过webhook与ansible)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 监听android 上的完成按键
- 下一篇: [HttpPost]和[AcceptVe