【发布时间】:2017-06-01 22:03:53
【问题描述】:
我有一个declarative 管道阶段,如下所示,
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'
}
【问题讨论】:
-
看起来 ant 不会将错误传播到管道。也许这可以帮助stackoverflow.com/questions/22395597/…。
-
谢谢haschibaschi,您评论中的页面给了我一些尝试的建议,即
echo %ERRORLEVEL%。我在答案中列出的解决方案之一中使用了它。
标签: jenkins ant jenkins-pipeline jenkins-blueocean