簡體   English   中英

jenkins 管道捕獲失敗並行構建的 build_job 信息

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

有誰知道如何在並行管道執行中捕獲失敗的作業編號,同時仍然具有 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

我現在能找到的唯一方法是使用“異常字符串”的值並將其拆分以獲取當前的內部版本號和名稱。 我不確定這是最強大的方法,但現在可以使用。 發布此回復以幫助他人。

您需要通過關閉異常傳播來避免拋出:

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

PS 有點晚了,但我自己剛到這里來找這個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM