Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions declarative-examples/simple-examples/whenBackToNormalMail.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pipeline {
/*
* This example shows how you can send "back to normal" mails.
* The post section checks if the build was failed (failure).
* If the build was failed an email is sent.
* If the build was successfull AND the previous build was failed,
* a "back to normal" mail is sent.
*/

agent any

stages {
stage("Hello") {
steps {
sh 'echo "Hello"'
}
}
}

post {
failure {
mail to: '[email protected]',
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Build failed: ${env.BUILD_URL}"
}

success {
if (currentBuild.previousBuild != null && currentBuild.previousBuild.result != 'SUCCESS') {
mail to: '[email protected]',
subject: "Pipeline Success: ${currentBuild.fullDisplayName}",
body: "Build is back to normal (success): ${env.BUILD_URL}"
}
}
}
}