How to get same Mailer behavior for Jenkins pipeline
I started using Jenkins' declarative pipelines. Now I want to have the same email behavior as defined in Using the Mailer Plugin:
- Each failed build starts a new email.
- A successful build after a failed (or unstable) build triggers a new email indicating the crisis is over.
- An unstable build after a successful build triggers a new email indicating that a regression exists.
- If not configured, each volatile build fires a new email indicating that the regression is still there.
I read about Notifications in Pipelines , but it doesn't notify about it per the rules above. In addition, it does not contain the console output portion in the message body in case of a build failure.
Does anyone know how to do this in a declarative pipeline?
+3
source to share
1 answer
In the following code, you can use the mailer plugin in the mail section. This provides the expected behavior:
pipeline {
agent any
stages {
stage('test') {
steps {
script {
// change to 'UNSTABLE' OR 'FAILED' to test the behaviour
currentBuild.result = 'SUCCESS'
}
}
}
}
post {
always {
step([$class: 'Mailer',
notifyEveryUnstableBuild: true,
recipients: "test@test.com",
sendToIndividuals: true])
}
}
}
+2
source to share