Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add whenBackToNormalMail.groovy example #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
37 changes: 37 additions & 0 deletions declarative-examples/simple-examples/whenBackToNormalMail.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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 {
script {
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}"
}
}
}
}
}