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