简体   繁体   English

jenkins 管道捕获失败并行构建的 build_job 信息

[英]jenkins pipeline catch build_job info for a failed parallel build

Does anyone know how to catch the failed job's number in a parallel pipeline execution while still have failFast feature working for short-circuiting of builds in the event of a job failure?有谁知道如何在并行管道执行中捕获失败的作业编号,同时仍然具有 failFast 功能以在作业失败时短路构建? I know i can kind-of make it work if i do "propagate = false" while running the build step but that kills the failFast feature, and i need that.我知道如果我在运行构建步骤时执行“propagate = false”,我可以让它工作,但这会破坏 failFast 功能,而我需要它。

For example, below is my code and i want the value of variable achild_job_info inside the catch block as well.例如,下面是我的代码,我也想要 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

The only way i could find out for now is to use the value of the 'exception string' and split it to get the current build number and name. 我现在能找到的唯一方法是使用“异常字符串”的值并将其拆分以获取当前的内部版本号和名称。 I am not sure that is the most robust way to do this but works for now. 我不确定这是最强大的方法,但现在可以使用。 Posting this reply to help others. 发布此回复以帮助他人。

You need to avoid throwing by turning off the exception propagation:您需要通过关闭异常传播来避免抛出:

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

PS A little late, but I just got here looking for this myself. PS 有点晚了,但我自己刚到这里来找这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM