gitlab与jenkins的自动化部署(通过webhook与ansible)
gitlab與jenkins的自動(dòng)化部署(通過webhook與ansilble)
1、部署介紹
gitlab服務(wù)器:192.168.1.49:80
jenkins服務(wù)器:192.168.1.49:8180
ps:由于兩個(gè)服務(wù)運(yùn)行在同一臺(tái)服務(wù)器上面,因此,為了保證jenkins服務(wù)器能拉取到 gitlab的代碼,把root的用戶的公鑰分別上傳到gitlab admin用戶跟jenkins admin用戶當(dāng)中去。jenkins我沒有使用默認(rèn)的端口8080,主要是我公司的gerrit架構(gòu)會(huì)用到這個(gè)8080端口,所以為了防止沖突,改為8180端口
?
2、gitlab安裝?
a) 第一步:安裝相應(yīng)的在依賴包(postfix或者sendmail),其中選擇internet site這種網(wǎng)絡(luò)smtp郵件服務(wù)器這種方式來發(fā)送郵件,其他一些依賴包: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)第三步,啟用配置,并且啟動(dòng) GitLab
操作命令:
sudo gitlab-ctl reconfigure
d) 第四步:打開網(wǎng)頁,進(jìn)行注冊(cè),使用默認(rèn)密碼
http://192.168.0.177:80
Username: rootPassword: 5iveL!fe
e) 第五步:2.1.6. Upload your license(EE版本需要認(rèn)證,CE) 這步我操作的時(shí)候是沒有的
Go toAdmin > Licenseand upload your.gitlab-licensefile.
Don't have a license yet? Get a subscription.
其實(shí)只要下載到gitlab ce包(ce是社區(qū)版,不用驗(yàn)證的),直接安裝就行了,啟動(dòng)命令為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) 注冊(cè)用戶
先開啟用戶注冊(cè)按鈕,用戶注冊(cè)完畢以后,關(guān)閉用戶注冊(cè)
?
4、配置jenkins拉取gitlab項(xiàng)目的賬號(hào)的sshkey
由于兩個(gè)服務(wù)運(yùn)行在同一臺(tái)服務(wù)器上面,因此,為了保證jenkins服務(wù)器能拉取到 gitlab的代碼,把root的用戶的公鑰分別上傳到gitlab admin用戶跟jenkins admin用戶當(dāng)中去。步驟我就不寫了!
?
?
5、配置jenkins項(xiàng)目
? 1、登錄192.168.1.49:8180
點(diǎn)擊新建:
?
依次填寫相關(guān)信息:(注意,項(xiàng)目安全這塊是在日常管理中才會(huì)用到,如果簡單測(cè)試可以忽略)
源碼管理:
?
觸發(fā)器:
我這里選擇得比較多,有push觸發(fā),也有merge觸發(fā)
構(gòu)建:(通過shell來構(gòu)建)
我這里是通過簡單的ansible來控制web服務(wù)器的壓縮包scp,tar解壓,還有指定軟聯(lián)接
#變量WORKSPACE、GIT_URL是jenkins默認(rèn)內(nèi)置的變量
jenkins這邊就配置完了
但是注意:jenkins跟gitlab怎么通信觸發(fā)呢?
大家請(qǐng)留意觸發(fā)器那塊有一句話:
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來連接兩者的有關(guān)系。
?
6、gitlab設(shè)置webhook
在對(duì)應(yīng)的gitlab項(xiàng)目設(shè)置當(dāng)中,設(shè)置webhooks
當(dāng)然,這里也可以設(shè)置triger事件:
保存后會(huì)在底部,生成webhook,點(diǎn)擊test,看jenkins界面是否觸發(fā)了!
登錄jenkins界面:192.168.1.49:8180
然后大功告成!
?
轉(zhuǎn)載于:https://www.cnblogs.com/to-be-rich/p/7655838.html
總結(jié)
以上是生活随笔為你收集整理的gitlab与jenkins的自动化部署(通过webhook与ansible)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 监听android 上的完成按键
- 下一篇: [HttpPost]和[AcceptVe