柚子快報(bào)邀請碼778899分享:運(yùn)維 DevOps(四)
柚子快報(bào)邀請碼778899分享:運(yùn)維 DevOps(四)
CD(二)
1. CD
Step 1 - 上傳代碼
Step 2 - 下載代碼
Step 3 - 檢查代碼
Step 4 - 編譯代碼
Step 5 - 上傳倉庫
Step 6 - 下載軟件
Step 7 - 制作鏡像
Step 8 - 上傳鏡像
Step 9 - 部署服務(wù)
2. 整體預(yù)覽
2.1 預(yù)覽
1. 修改代碼
2. 查看sonarqube檢查結(jié)果
3. 查看nexus倉庫
4. 查看harbor倉庫
5. 整體效果
2.2 pipeline完整版
3. 寫在最后...
1. CD
參考前面的流程圖,我們正式開始CD的流程
Step 1 - 上傳代碼
安裝git 參考 Windows安裝Git圖文教程
配置IDEA 參考 IDEA配置Git,以GitHub遠(yuǎn)程倉庫為例
提交代碼到本地 Commit
gitlab賬號密碼:root/Newm123@
gitlab創(chuàng)建項(xiàng)目,復(fù)制URL
IDEA push代碼 會提示輸入gitlab URL 賬號密碼
提交完成
Step 2 - 下載代碼
在jenkins上創(chuàng)建pipeline項(xiàng)目
創(chuàng)建節(jié)點(diǎn),并連接節(jié)點(diǎn)
配置jenkins gitlab(不配置也可以,因?yàn)槲覀冊趐ipeline中也需要配置) Dashboard > Manage Jenkins >System
配置觸發(fā)器(不配置也可以,在pipeline中也可以配置)
pipeline片段
pipeline {
agent {
node {
label 'node-133'}
}
stages {
stage('Build') {
steps {
// Get some code from a GitHub repository
git credentialsId: 'd3cb7c68-63e5-46d6-a505-d73a89902758', url: 'http://192.168.17.132:8929/devs/myjava.git'
// Run Maven on a Unix agent.
sh "mvn -Dmaven.test.failure.ignore=true clean package"
// To run Maven on a Windows agent, use
// bat "mvn -Dmaven.test.failure.ignore=true clean package"
}
}
}
}
此處把mvn打包也一同配置了,并進(jìn)行簡單測試
[root@node-133 MyJava-Pipeline]# ll target/
total 4
drwxr-xr-x 2 root root 29 Jul 19 05:25 classes
drwxr-xr-x 3 root root 25 Jul 19 05:25 generated-sources
drwxr-xr-x 2 root root 28 Jul 19 05:25 maven-archiver
drwxr-xr-x 3 root root 35 Jul 19 05:25 maven-status
drwxr-xr-x 4 root root 54 Jul 19 05:25 MyJava-latest
-rw-r--r-- 1 root root 3054 Jul 19 05:25 MyJava-latest.war
[root@node-133 MyJava-Pipeline]# pwd
/opt/jenkins/workspace/MyJava-Pipeline
Step 3 - 檢查代碼
啟動(dòng)sonarqube,登錄并設(shè)置密碼 http://192.168.17.133:9090 admin/password
部署sonar-scanner
unzip sonar-scanner-cli-4.7.0.2747-linux.zip
cd sonar-scanner-4.7.0.2747-linux/
vim conf/sonar-scanner.properties
[root@dbc-server-554 sonar-scanner-4.7.0.2747-linux]# cat conf/sonar-scanner.properties
#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here
#----- Default SonarQube server
sonar.host.url=http://localhost:9090
#----- Default source code encoding
sonar.sourceEncoding=UTF-8
ln -sv /root/docker/sonar/sonar-scanner-4.7.0.2747-linux /usr/local/sonar-scanner
export PATH=/usr/local/sonar-scanner/bin:$PATH
source .bashrc
[root@dbc-server-554 sonar-scanner-4.7.0.2747-linux]# sonar-scanner -h
INFO:
INFO: usage: sonar-scanner [options]
INFO:
...
生成掃描命令
mvn clean verify sonar:sonar \
-Dsonar.projectKey=MyJava \
-Dsonar.host.url=http://192.168.17.133:9090 \
-Dsonar.login=6b1dddd3274606082753ff907ee1b0380c28298a
部署jenkins pipeline
pipeline片段
//定義http方法
def HttpReq(reqType,reqUrl,reqBody){
sonarServer = "http://192.168.17.133:9090/api"
// 可以不加authentication認(rèn)證,因?yàn)槟J(rèn)不需要
result = httpRequest consoleLogResponseBody: true,
httpMode: 'GET',
responseHandle: 'NONE',
url: "${sonarServer}/${reqUrl}"
// customHeaders:[[name:'Authorization', value:"Basic ${credentials}"]]
return result
}
//獲取Sonar質(zhì)量閾狀態(tài)
def GetProjectStatus(projectName){
apiUrl = "project_branches/list?project=${projectName}"
response = HttpReq("GET",apiUrl,'')
response = readJSON text: """${response.content}"""
result = response["branches"][0]["status"]["qualityGateStatus"]
println
柚子快報(bào)邀請碼778899分享:運(yùn)維 DevOps(四)
精彩內(nèi)容
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。