1. BlueOcean是什麼?
Jenkins是一款Java開發的跨平臺持續集成和持續發佈的開源項目,它具有如下特徵:
安裝及遷移方便:安裝直接部署war包,遷移只需替換JENKINS_HOME目錄。
配置方便:可視化後臺操作。
豐富的插件生態圈:比如git, junit, jacoco等。
可擴展:自定義插件。
分佈式:支持Master-Slave。
Jenkins已經作爲各大公司進行CI/CD的首選工具。
Jenkins UI從2006年-2016年,幾乎沒有變化。
爲了適應Jenkins Pipeline和 Freestyle jobs任務,Jenkins推出了BlueOcean UI,其目的就是讓程序員執行任務時,降低工作流程的複雜度和提升工作流程的清晰度,它具有如下特徵:
清晰的可視化,對CI/CD pipelines, 可以快速直觀的觀察項目pipeline狀態。
pipeline可編輯(開發中),可視化編輯pipeline,現在只能通過配置中Pipeline的Pipeline script編輯。
pipeline精確度,通過UI直接介入pipeline的中間問題。
集成代碼分支和pull請求。
2. BlueOcean使用
BlueOcean是以插件的形式存在,需要Jenkins版本2.7.*以上,目前還是beta版本,功能不是很完善。
安裝步驟:
系統管理->管理插件->可選插件,選擇BlueOcean beta->restart。
安裝完畢後,BlueOcean入口在菜單欄居中: "Open Blue Ocean",進去後可以看到全新的UI:
我們新建一個Pipeline項目,配置如下:
其中最重要的是定義pipeline script:
node { stage('Clone Code') { // for display purposes // Get some code from a GitHub repository git 'https://github.com/trautonen/coveralls-maven-plugin.git/' } stage('Code Analysis') { sh "mvn clean" sh "infer -- mvn compile" } stage('Testing') { sh "mvn test" junit 'target/surefire-reports/TEST-*.xml' } stage('Package') { sh "'mvn' -Dmaven.test.skip=true package" archive 'target/*.jar' } stage('Deploy') { echo 'pipeline success' } }
pipeline script定義了整個Pipeline的流程,stage('Clone Code')
中Clone Code
就是pipeline中的第一步,依次類推。
每一步做具體任務,比如git 'https://github.com/trautonen/coveralls-maven-plugin.git/'
就是去拉源碼,具體的語法可以參考Pipeline Syntax:
配置完任務後,進入BlueOcean,點擊Run:
開始執行pipeline:
執行結束後,pipeline順利通過:
查看Tests結果(對應pipeline script中junit 'target/surefire-reports/TEST-*.xml'
):
查看打包結果(對應pipeline script中archive 'target/*.jar'
):
執行過程很流暢,每個步驟通過清晰的可視化過程,使用者能快速的定位流程中的問題。
3.BlueOcean Roadmap
現在BlueOcean還是beta版本,支持的功能比較侷限,比如不支持參數化,不支持指定具體slave執行等等,我們看下BlueOcean Roadmap:
相信Jenkins BlueOcean功能會越來越完善,而使用Jenkins BlueOcean會大大提高CI/CD工作效率。