Hey there,
I have a multibranch pipeline in Jenkins 2.440.3, with a complex post:
- If the build fails (which I hope it is triggered when the compilation fails) is set to send a message on teams saying it so;
- If the build is unstable (which I hope it is tied with the
junit
plugin and it is related to the tests), we parse the reports and properly post a list of errors on teams.
Because we have an integration with Bitbucket, we need to set the unstable status to fail, so it appears properly on BB interface. Because I don’t want the unstable to trigger the failure post, I set up a post for unstable that just changes the pipeline result in the end.
The thing is: It seems that when the unstable post changes the result to failure, it also triggers the failure post, and we end up with two messages.
Does this actually happens? Is there a better way to handle this situation?
Here’s our post
post {
// A failure may happen when the build failed (or we broke this script)
failure {
script {
message = "The **build** of commit ${env.GIT_COMMIT} is **bad, no good, nuh-uh**.\n(This is before we could run any tests.)"
office365ConnectorSend webhookUrl: WEBHOOK,
message: message,
color: '#e50f0f'
return
}
}
// Unstable happens when the tests fails. That means the call of `junit`
// returned a health check of "BAD".
unstable {
script {
// We need to set the build status to FAILURE 'cause, otherwise, Bitbucket
// will not mark the build as bad in its interface.
currentBuild.result = 'FAILURE'
return
}
}
always {
script {
echo "Current status: ${currentBuild.result}"
if (currentBuild.result == 'NOT_BUILT') {
currentBuild.result = 'ABORTED'
}
}
}
}