如何使用$ {currentBuild.result}表示“成功”而不是“空”

时间:2018-10-02 08:08:08

标签: jenkins jenkins-declarative-pipeline

我的Jenkins声明性管道具有以下后期处理措施:

mail to: '<snip>',
        subject: "Status of pipeline: ${currentBuild.fullDisplayName}",
        body: "${env.BUILD_URL} has result ${currentBuild.result}"

构建成功后,电子邮件正文的内容为:

<job name> has result null

我了解到作业成功时$ {currentBuild.result}“的值为null,但这对用户来说不方便。建议打印“ SUCCESS”(或“ FAILURE”等)的方式是什么?在正文消息中?

2 个答案:

答案 0 :(得分:9)

改为使用${currentBuild.currentResult}

请参见https://qa.nuxeo.org/jenkins/pipeline-syntax/globals#currentBuild

  

currentResult

     

通常为成功,不稳定或失败。永远不会为空。

另请参见https://issues.jenkins.io/browse/WEBSITE-364

答案 1 :(得分:2)

您可以在管道的发布步骤中添加邮件步骤,如下所示:

pipeline {
agent any
stages {
    stage('Example Test') {
        steps {
            echo 'Hello, JDK'
        }
       }
     }
post {
 success {
     echo "${env.BUILD_URL} has result success"
      }
 failure {
     echo "${env.BUILD_URL} has result fail"
      }
     }
 }