2
A
回答
1
不,流水線的正常流程是從頭到尾。 然而,你可以做的是測試你的成功狀態,而不是調用你的代碼的其餘部分,在一個如果或類似的東西。函數可以幫助您輕鬆實現,例如:
node() {
// Part 1
def isSuccess = part1();
if(!isSuccess) {
part2()
}
}
// Part 2
def function part2() {
// Part 2 code
}
然而,你應該小心那種東西,也許這更能突顯出您的管道設計不當。如果這不是您想要的,請提供更多詳細信息,例如用例。
0
首先,我不知道這樣的一個步驟。
但是,如果應該成功,您可以使用error
步驟中止具有特定消息的構建。在try{}catch(){}
塊中捕獲此錯誤,檢查消息並將構建狀態設置爲成功。
1
正如在其他答覆中所說的那樣,沒有以這種方式中止的步驟。正如克里斯托弗建議你可以在中止代碼周圍使用try-catch並使用error()。我認爲您需要跟蹤您的構建的中止狀態 - 您可以在管道中全局定義中止方法來設置此狀態併產生錯誤,以便放棄您舞臺中的其他步驟。
如果您使用了聲明式管道,則可以在後面的階段對錶達式使用'when'聲明,以便在設置中止狀態時不執行聲明。
我對這個問題自己,所以我制定了一個管道,這是否在這裏的一個例子:
/**
* Tracking if the build was aborted
*/
Boolean buildAborted = false
/**
* Abort the build with a message
*/
def abortBuild = { String abortMessage ->
buildAborted = true
error(abortMessage)
}
pipeline {
agent any
parameters {
string(name: 'FailOrAbort', defaultValue: 'ok', description: "Enter 'fail','abort' or 'ok'")
}
stages {
stage('One') {
steps {
echo "FailOrAbort = ${params.FailOrAbort}"
script {
try {
echo 'Doing stage 1'
if(params.FailOrAbort == 'fail') {
echo "This build will fail"
error("Build has failed")
}
else if(params.FailOrAbort == 'abort') {
echo "This build will abort with SUCCESS status"
abortBuild("This build was aborted")
}
else {
echo "This build is a success"
}
echo "Stage one steps..."
}
catch(e) {
echo "Error in Stage 1: ${e.getMessage()}"
if(buildAborted) {
echo "It was aborted, ignoring error status"
}
else {
error(e.getMessage())
}
}
}
}
post {
failure {
echo "Stage 1 failed"
}
}
}
stage('Two') {
when {
expression {
return !buildAborted
}
}
steps {
echo "Doing stage 2"
}
}
stage('Three') {
when {
expression {
return !buildAborted
}
}
steps {
echo "Doing stage 3"
}
}
}
post {
always {
echo "Build completed. currentBuild.result = ${currentBuild.result}"
}
failure {
echo "Build failed"
}
success {
script {
if(buildAborted) {
echo "Build was aborted"
} else {
echo 'Build was a complete success'
}
}
}
unstable {
echo 'Build has gone unstable'
}
}
}
作爲一個方面說明有一個屬性「currentBuild.result」你可以調整管道,但一旦設置爲'失敗'它不能被清除回'成功' - 詹金斯模型不允許它AFAIK。
相關問題
- 1. 我可以獲得Jenkins管道中前一階段構建的狀態嗎?
- 2. 如何在Jenkins管道中獲取成功/失敗的構建信息?
- 3. 構建狀態jenkins
- 4. Jenkins - 構建狀態
- 5. 在Jenkins管道中獲取build.gradle中設置的變量構建
- 6. 阻止Jenkins在每個成功構建中創建git標記
- 7. Jenkins管道作業構建
- 8. jenkins管道獲得價值
- 9. 如何通過jenkins中的另一個管道作業構建並獲取管道作業的構建日誌
- 10. 如何中止Jenkins管道構建,如果標籤不匹配
- 11. 如何獲取自jenkins管道上次成功構建以來的更改?
- 12. 從Jenkins 2.0中的並行執行訪問構建管道
- 13. Jenkins獲取中止構建的用戶
- 14. Jenkins有沒有辦法讓「構建RED狀態的小時數」獲得構建?
- 15. 嘗試在Jenkins管道中構建Docker容器時,在構建時獲得「can not stat」錯誤,但爲什麼?
- 16. 在GitHub中顯示Jenkins管道狀態對拉請求
- 17. Jenkins構建作業即使成功也沒有完成
- 18. 並行Jenkins管道
- 19. Maven構建在Jenkins中中止
- 20. Jenkins構建管道調度觸發器
- 21. 如何獲得管道中特定階段的狀態
- 22. Jenkins管道DSL自動中止輸入
- 23. Jenkins構建成功通過集成測試後不會停止
- 24. 如何在Jenkins聲明式管道中處理每晚構建
- 25. 在Jenkins管道中構建特定版本
- 26. nodejs服務器在jenkins中沒有給出成功狀態
- 27. 如何在jenkins管道中傳遞並行構建下游的參數
- 28. 我可以在Jenkins管道中創建動態階段嗎?
- 29. 如何獲得在teamcity中執行構建步驟的狀態?
- 30. 在Jenkins管道作業中無法獲取生成參數
用於描述'currentBuild.result'生命週期的榮譽 - 讓我不止一次地絆倒了我。 – rbellamy