更新:这似乎是Pipeline: Declarative
插件版本1.3.5
中引入的错误-降级为1.3.4.1
可解决此问题。票证位于:
在远程执行器上使用时,如何获取构建的真实状态?
困境:
currentBuild.result
为NULL,currentBuild.currentResult
为成功在远程执行器上执行构建时,如何访问实际的故障?
代码视图:
pipeline {
agent any
stages {
stage("test run") {
steps {
sh "exit 1"
}
}
}
post {
always {
echo "I always run: ${currentBuild.result} <> ${currentBuild.currentResult}"
}
success {
echo "I'm successful: ${currentBuild.result} <> ${currentBuild.currentResult}"
}
failure {
echo "I failed: ${currentBuild.result} <> ${currentBuild.currentResult}"
}
fixed {
echo "I'm fixed!: ${currentBuild.result} <> ${currentBuild.currentResult}"
}
}
}
输出:
[Pipeline] Start of Pipeline
[Pipeline] node
Running on build-096575a3-e6af-4fff-9ca1-84cc46ba4b86-f9b8d29c in /var/vcap/data/jenkins-slave/workspace/test-job
[Pipeline] {
[Pipeline] stage
[Pipeline] { (test run)
[Pipeline] sh
+ exit 1
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] echo
I always run: null <> SUCCESS
[Pipeline] echo
I failed: null <> SUCCESS
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE
答案 0 :(得分:1)
(为我的问题发布“官方答复”)
这是Pipeline: Declarative
插件版本1.3.5
中引入的“错误”-降级为1.3.4.1
可解决此问题。票证位于:
在用户和开发人员之间来回回荡是否确实是一个错误。开发人员建议不要再使用currentBuild.result
,但许多人指出这是一次BC中断,并导致很多问题。
该问题已标记为Critical
-可能会回滚或重新开发以便更好地实施。
如果您依靠currentBuild.result
或currentBuild.currentResult
的此功能,建议您对此错误发表评论。
答案 1 :(得分:0)
您可以使用try catch:
try {
sh "exit 1"
currentBuild.result = 'SUCCESS'
}catch (Exception err) {
currentBuild.result = 'FAILURE'
}