我正在尝试在jenkins管道中并行运行多个构建并获得这些构建的结果。我的代码看起来像
runWrappers = []
script {
def builds = [:]
builds['a'] = { runWrappers += build job: 'jobA', parameters: /* params here*/ }
builds['b'] = { runWrappers += build job: 'jobB', parameters: /* params here*/ }
builds['c'] = { runWrappers += build job: 'jobC', parameters: /* params here*/ }
builds['d'] = { runWrappers += build job: 'jobD', parameters: /* params here*/ }
parallel builds
// All the builds are ran in parallel and do not exit early if one fails
// Multiple of the builds could fail on this step
}
如果没有失败,管道将继续进入其他阶段。如果失败,将抛出异常,并且以下构建后的代码将立即运行
post {
always {
script {
def summary = ''
for (int i; i < runWrappers.size(); i++) {
def result = runWrappers[i].getResult()
def link = runWrappers[i].getAbsoluteUrl()
summary += "Build at: " + link + " had result of: " + result
}
/* Code to send summary to external location */
}
}
}
这在很大程度上起作用。问题是这段代码只打印出导致SUCCESS的构建的结果,因为失败的构建会在返回对runWrapper的引用之前抛出异常。
有没有办法获得对runWrapper或类似的引用,它可以在失败的构建中提供信息(主要是url和结果)?或者有没有办法在我开始构建之前获得这样的引用并导致异常?
答案 0 :(得分:2)
尝试使用propagate: false
:
build job: 'jobA', propagate: false, parameters: /* params here*/
但在这种情况下,您的parallel
将不再失败。