How to use ${currentBuild.result} to indicate "SUCCESS" not "null"

DavidA picture DavidA · Oct 2, 2018 · Viewed 44.2k times · Source

My Jenkins declarative pipeline has the following post action:

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

When the build succeeds the content of the email body is:

<job name> has result null

I understand that the value of ${currentBuild.result}" is null when the job succeeds, but this isn't convenient for the user. What is the recommended way of printing "SUCCESS" (or "FAILURE" etc) in the body message?

Answer

PKo picture PKo · Nov 14, 2018

Use ${currentBuild.currentResult} instead.

currentResult

typically SUCCESS, UNSTABLE, or FAILURE. Will never be null.

The syntax of the available global variables is available at ${YOUR_JENKINS_URL}/pipeline-syntax/globals. See more info about globals in Jenkins documentation.

Also see https://issues.jenkins.io/browse/WEBSITE-364