1
我有一個declarative流水線階段像下面,詹金斯管道建設使用Jenkinsfile沒有失敗
stage('build') {
steps {
echo currentBuild.result
script {
try {
bat 'ant -f xyz\\build.xml'
} catch (err) {
echo "Caught: ${err}"
currentBuild.result = 'FAILURE'
}
}
echo currentBuild.result
}
}
我期待,因爲生成與下面的消息未能管道失敗。
BUILD FAILED
C:\...\build.xml:8: The following error occurred while executing this line:
C:\...\build.xml:156: The following error occurred while executing this line:
C:\...\build.xml:111: Problem creating jar: C:\...\xyz.war (The system cannot find the path specified) (and the archive is probably corrupt but I could not delete it)
currentBuild.result在我打印它的時候都是空的。
螞蟻叫錯了嗎?
爲什麼返回狀態不是通過管道自動捕獲的?
螞蟻通話可否不返回失敗狀態?
我試過catchError而不是try..catch,仍然沒有捕獲到構建失敗。
catchError {
bat 'ant -f xyz\\build.xml'
}
看起來像螞蟻不會傳播錯誤到管道。也許這可以幫助https://stackoverflow.com/questions/22395597/propagating-exit-code-from-execd-batch-file-back-to-ant。 – haschibaschi
謝謝haschibaschi,您評論中的頁面給了我一些嘗試的指針,即'echo%ERRORLEVEL%'。我在下面列出的解決方案之一中使用了它。 – user2891264