[英]How to fail master Jenkins pipeline job if downstream jobs fails
我有一個Jenkins管道master
作業,它觸發2個作業buildjob1
和buildjob2
。
我的master
道工作很簡單,如下所示:
stage ("Test") {
build (job: buildJob1,
parameters: [
string(name: 'A', value: "AA),
string(name: 'B', value: "BB),
],
propagate: false)
build (job: buildJob2,
parameters: [
string(name: 'A', value: "AA"),
],
propagate: false)
}
cleanWs()
}
我希望兩個下游作業都運行,並且如果任何作業失敗,則將主作業標記為不穩定/失敗。
我如何通過管道做到這一點?
如果作業不相互依賴,請與FailFast參數並行使用-並且您必須刪除傳播選項(或將其設置為true)
stage ("Test") {
parallel buildJob1: {
build (job: buildJob1,
parameters: [
string(name: 'A', value: "AA),
string(name: 'B', value: "BB),
])
}, buildJob2: {
build (job: buildJob2,
parameters: [
string(name: 'A', value: "AA"),
])
}, failFast: false
}
cleanWs()
}
編輯:正如您所評論的,作業只能按順序運行,我們必須手動檢查作業結果並手動設置管道作業結果。 這樣,我們可以根據需要調用任意多個順序的Job:
stage("buildjob1") {
result = build (job: buildJob1,
parameters: [
string(name: 'A', value: "AA),
string(name: 'B', value: "BB),
], propagate=false)
// Inspect result
if(result == 'FAILURE') {
echo "buildjob1 failed"
currentBuild.result = 'UNSTABLE' // of FAILURE
}
}
stage("buildjob2") {
result = build (job: buildJob2,
parameters: [
string(name: 'A', value: "AA"),
], propagate=false)
// Inspect result
if(result == 'FAILURE') {
echo "buildjob2 failed"
currentBuild.result = 'UNSTABLE' // of FAILURE
}
}
stage("cleanup") {
// Call your cleanup
cleanWs()
}
您可以將此階段包裝在try catch中,如果有任何錯誤==>則將當前構建狀態設置為FAILURE
try {
stage("Test") {
build (job: buildJob1,
parameters: [
string(name: 'A', value: "AA"),
string(name: 'B', value: "BB"),
],
propagate: false)
build (job: buildJob2,
parameters: [
string(name: 'A', value: "AA"),
string(name: 'B', value: "BB"),
],
propagate: false)
}
} catch (error) {
currentBuild.result='FAILURE'
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.