經過multibranch類型的pipeline job使得對於多個branch的支持更加簡單。只須要建立一個multibranch job,jenkins將自動地爲全部的branch建立job。node
文章來自:http://www.ciandcd.com
文中的代碼來自能夠從github下載: https://github.com/ciandcdgit
文中用到的repo:https://github.com/ciandcd/example_jenkins_multibranch.git, 包含了master和b1兩個branches。github
1. Jenkinsfile內容以下:ui
https://github.com/ciandcd/example_jenkins_multibranch/blob/b1/Jenkinsfile
https://github.com/ciandcd/example_jenkins_multibranch/blob/master/Jenkinsfileurl
node (){
stage 'Build and Test'
env.PATH = "${tool 'M3'}/bin:${env.PATH}"
checkout scm
sh 'mvn clean package'
}插件
注意這裏的checkout scm,不須要指定具體的git url。blog
2. 新建multibranch pipeline jobip
2. 自動爲每一個branch生成jobci
在multibranch pipeline job保存後,jenkins自動地檢查全部的branch,且自動地爲全部的branch建立job。jenkins
例如上面的job,自動地生成了文件夾pipeline_multibranch,且在此文件夾下自動地爲master和b1生成了job。
而後能夠自由的選擇運行某些branch的job。
3. GitHub Organization or New Item → Bitbucket Team
相似地,還能夠安裝插件github organiztion 或 bitbucket team來自動地爲全部的項目建立multibranch pipeline job。