【问题标题】:jenkins pipeline catch build_job info for a failed parallel buildjenkins 管道捕获失败的并行构建的 build_job 信息
【发布时间】:2017-04-28 21:31:20
【问题描述】:

有谁知道如何在并行管道执行中捕获失败的作业编号,同时在作业失败的情况下仍然有 failFast 功能用于短路构建?我知道如果我在运行构建步骤时执行“propagate = 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

【问题讨论】:

    标签: jenkins jenkins-pipeline


    【解决方案1】:

    我现在唯一能找到的方法是使用“异常字符串”的值并将其拆分以获取当前的内部版本号和名称。我不确定这是最可靠的方法,但目前有效。发布此回复以帮助他人。

    【讨论】:

      【解决方案2】:

      你需要通过关闭异常传播来避免抛出:

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

      附:有点晚了,但我自己就是来找这个的。

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 2015-10-12
      • 2017-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多