如何让流水线作业等待所有触发的并行作业? [英] How to make Pipeline job to wait for all triggered parallel jobs?

查看:23
本文介绍了如何让流水线作业等待所有触发的并行作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Groovy 脚本作为 Jenkins 流水线作业的一部分,如下所示:

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

这篇关于如何让流水线作业等待所有触发的并行作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆