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?
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.