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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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: 'user@mail.com',
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Build failed: ${env.BUILD_URL}"
}

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