From 16347e4ea6a790e75f936cba022cfb3fb5a91c91 Mon Sep 17 00:00:00 2001 From: Michal Kovarik Date: Mar 11 2020 10:32:53 +0000 Subject: Send email in case of failed run Send email notification about failed result for postmerge, trigger on tag and greenwave promotion. --- diff --git a/roles/c3i/templates/build.Jenkinsfile b/roles/c3i/templates/build.Jenkinsfile index 5581b97..6c8aa28 100644 --- a/roles/c3i/templates/build.Jenkinsfile +++ b/roles/c3i/templates/build.Jenkinsfile @@ -261,10 +261,6 @@ pipeline { def recipient = params.MAIL_ADDRESS def subject = "Jenkins job ${env.JOB_NAME} #${env.BUILD_NUMBER} failed." def body = "Build URL: ${env.BUILD_URL}" - if (env.PR_NO) { - subject = "Jenkins job ${env.JOB_NAME}, PR #${env.PR_NO} ${status}." - body += "\nPull Request: ${env.PR_URL}" - } emailext to: recipient, subject: subject, body: body } catch (e) { echo "Error sending email: ${e}" diff --git a/roles/c3i/templates/greenwave-promote.Jenkinsfile b/roles/c3i/templates/greenwave-promote.Jenkinsfile index d3e9d38..feff6c0 100644 --- a/roles/c3i/templates/greenwave-promote.Jenkinsfile +++ b/roles/c3i/templates/greenwave-promote.Jenkinsfile @@ -76,4 +76,21 @@ pipeline { } } } + post { + failure { + script { + // sending email + if (params.MAIL_ADDRESS){ + try { + def recipient = params.MAIL_ADDRESS + def subject = "Jenkins job ${env.JOB_NAME} #${env.BUILD_NUMBER} failed." + def body = "Build URL: ${env.BUILD_URL}" + emailext to: recipient, subject: subject, body: body + } catch (e) { + echo "Error sending email: ${e}" + } + } + } + } + } } diff --git a/roles/c3i/templates/trigger-on-tag.Jenkinsfile b/roles/c3i/templates/trigger-on-tag.Jenkinsfile index be3cc32..526485c 100644 --- a/roles/c3i/templates/trigger-on-tag.Jenkinsfile +++ b/roles/c3i/templates/trigger-on-tag.Jenkinsfile @@ -42,4 +42,21 @@ pipeline { } {{ task_var_integration_test }} } + post { + failure { + script { + // sending email + if (params.MAIL_ADDRESS){ + try { + def recipient = params.MAIL_ADDRESS + def subject = "Jenkins job ${env.JOB_NAME} #${env.BUILD_NUMBER} failed." + def body = "Build URL: ${env.BUILD_URL}" + emailext to: recipient, subject: subject, body: body + } catch (e) { + echo "Error sending email: ${e}" + } + } + } + } + } }