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?
Navigate to the Jenkins dashboard and select Build History. This timeline displays your build history. This table displays a list of your past builds, time since build and the status of each build.
currentBuild is a global variable that may be used to refer to the currently running build.
Pipeline jobs can be stopped by sending an HTTP POST request to URL endpoints of a build. BUILD ID URL/stop - aborts a Pipeline. BUILD ID URL/term - forcibly terminates a build (should only be used if stop does not work).
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
You can add mail step inside post step in pipeline as below :
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"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With