如何使管道作业等待所有触发的并行作业? [英] How to make Pipeline job to wait for all triggered parallel jobs?
问题描述
我将Groovy脚本作为Jenkins中Pipeline工作的一部分,如下所示:
I've Groovy script as part of the Pipeline job in Jenkins as below:
node {
stage('Testing') {
build job: 'Test', parameters: [string(name: 'Name', value: 'Foo1')], quietPeriod: 2, wait: false
build job: 'Test', parameters: [string(name: 'Name', value: 'Bar1')], quietPeriod: 2, wait: false
build job: 'Test', parameters: [string(name: 'Name', value: 'Baz1')], quietPeriod: 2, wait: false
build job: 'Test', parameters: [string(name: 'Name', value: 'Foo2')], quietPeriod: 2, wait: false
build job: 'Test', parameters: [string(name: 'Name', value: 'Bar2')], quietPeriod: 2, wait: false
build job: 'Test', parameters: [string(name: 'Name', value: 'Baz2')], quietPeriod: 2, wait: false
}
}
由于wait
标志设置为false
,因此它并行执行多个其他自由式作业.但是,我希望所有作业完成后才能完成呼叫者作业.目前,Pipeline作业会触发所有作业并在几秒钟后自行完成,这不是我想要的,因为我无法跟踪总时间,而且我无法一次性取消所有触发的作业.
which executes multiple other freestyle jobs in parallel, because of wait
flag being set to false
. However I'd like for the caller job to finish when all jobs are finished. Currently the Pipeline job triggers all the jobs and finishes it-self after few seconds which is not what I want, because I cannot track the total time and I don't have ability to cancel all triggered jobs at one go.
在并行完成所有并行作业后,如何纠正上述脚本以完成管道作业?
How do I correct above script for Pipeline job to finish when all jobs in parallel are completed?
我尝试将构建作业包装在waitUntil {}
块中,但是没有用.
I've tried to wrap build jobs in waitUntil {}
block, but it didn't work.
推荐答案
您应使用管道 parallel 表达式,该表达式将等待所有产生的作业/子任务完成:
You should use pipeline parallel expression, which will wait for all spawned jobs / subtasks to complete:
stage('testing') {
def branches = [:]
for(i = 0; i < params.size(); i += 1) {
def param = params[i]
branches["Test${i}"] = {
build job: 'Test', parameters: [string(name: 'Name', value: param)], quietPeriod: 2
}
}
parallel branches
}
您可以在管道文档中的 jenkins.io
You can find some more examples in pipeline docs at jenkins.io
这篇关于如何使管道作业等待所有触发的并行作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!