Jenkins管道捕获构建build_job信息,用于失败的并行构建



有人知道如何在并行管道执行中捕获失败的作业号码,而在工作失败的情况下仍然具有用于短路构建的失败farface功能?我知道,如果我在运行构建步骤时"繁殖= false",我可以使它起作用,但这会杀死Failfast功能,我需要。

例如,以下是我的代码,我也希望catch块内的可变achild_job_info的值。

build_jobs = [“Build_A”, “ Build_B”, “ Build_C”]
def build_job_to_number_mappings = [:]
// in this hashmap we'll place the jobs that we wish to run
def branches = [:] 
def achild_job_info = ""
def abuild_number = ""
for (x in build_jobs) {
    def abuild = x 
    branches[abuild] = { 
        stage(abuild){
            retry(2) {
                try {
                    achild_job_info = build job: abuild
                    echo “ achild_job_info”  // —>  this gives: org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper@232601dc
                    abuild_number = achild_job_info.getId()
                    build_job_to_number_mappings[abuild] = achild_job_info.getNumber()
                } catch (err) {
                    echo “ achild_job_info: ${achild_job_info } “  // —> This comes empty. I want the runwrapper here as well, just like in the try block. 
                    abuild_job_number = abuild_job_info.getId()
                    build_job_to_number_mappings[abuild] = achild_job_info.getNumber()
                } // try-catch
        } // stage
   } // branches
} // for
branches.failFast = true
parallel branches

我暂时可以找到的唯一方法是使用'异常字符串'的值并将其拆分以获取当前的构建编号和名称。我不确定这是最强大的方法,但现在可以使用。发布此答复以帮助他人。

您需要通过关闭异常传播来避免投掷:

achild_job_info = build job: abuild, propagate: false
if(achild_job_info.result == "SUCCESS") { ...

P.S。有点晚了,但我只是来这里寻找这个。

最新更新