动态的创建 一个 并行的 流水线。并且可以设置agent的。
例1
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
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
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
}
}
}
}
}
版权声明:本文为mmh19891113原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。