I've come across older questions on this topic. Namely
But, by now, I'd expect the Jenkins Pipeline to have this functionality baked, rather than hacked, in.
When running a post
script in a Jenkins Pipeline is there any way to find the build failure? e.g. Via an environmental variable, currentBuild
, etc.
pipeline {
agent none
stages {
stage("Validate") {
parallel {
stage("Ubuntu") {
agent {
label "UBUNTU"
}
steps {
sh "cause failure"
}
}
}
}
}
post {
failure {
sendFailureMessage(`failure reason here`)
}
aborted {
sendFailureMessage(`failure reason here`)
}
unstable {
sendFailureMessage(`failure reason here`)
}
}
}