动态的创建 一个 并行的 流水线。并且可以设置agent的。
例1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| pipeline { agent any stages { stage('BuildAll') { parallel { stage('build-win') { steps { sh "env | grep -i NODE_NAME" runParallel items: ("a".."d").collect { "Win-${it}" } } }
stage('build-Mac') { steps { sh "env | grep -i NODE_NAME" runParallel items: ("a".."d").collect { "Mac-${it}" } } } } } } }
def runParallel(args) { parallel args.items.collectEntries { name -> [ "${name}": { node('master') { stage("${name}") { stage("${name}-a") { sh "env | grep -i NODE_NAME" } stage("${name}-b") { sh "env | grep -i NODE_NAME" } } } } ] } }
|
例2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| pipeline { agent any stages { stage('build') { steps { runParallel items: ("a".."f").collect { "Stage ${it}" } } } } }
def runParallel(args) { parallel args.items.collectEntries { name -> [ "${name}": { stage("${name}") { echo name } }]} }
|
例3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| pipeline { agent {label 'master'} stages { stage('Build apps(s)') { steps { script { def nodeList = "bf-01,bf-02,bf-03".split(",").findAll { it }.collect { it.trim() } def jobs = [:]
for (int i = 0; i < nodeList.size(); i++) { def app = nodeList[i] jobs["jobs-${app}"] = { node('another-master') { stage("Build ${app}") { echo "Build ${app}" } } } } parallel jobs } } } } }
|