From 724179c07a8dac811d8a0e0dbbdc2da20c530c0a Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Sun, 21 Nov 2021 17:16:36 +0000 Subject: [PATCH] Use extended email to send emails on failed build --- build/postactions.groovy | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/build/postactions.groovy b/build/postactions.groovy index f9e0b72..740bc0a 100644 --- a/build/postactions.groovy +++ b/build/postactions.groovy @@ -138,19 +138,23 @@ def performSuccessfulBuildActions() { deployjob(buildselector, postbuildactions, 'Release to git', 'RELEASE_TO_GIT_JOB') } -def sendemails(emailtolist) { - def emailbody = """ - Failed build: ${JOB_NAME} ${BUILD_DISPLAY_NAME} : ${BUILD_URL} +def sendemails(emailinfo) { + def emailtolist = emailinfo['To'] - Console output: ${BUILD_URL}console - """ - for(emailto in emailtolist) { - mail( - subject: "[Jenkins] Failed build: ${JOB_NAME} ${BUILD_DISPLAY_NAME}", - body: emailbody, - to: emailto - ) - echo "Send email to: ${emailto}" + if (emailtolist) { + def emailbody = """ + Failed build: ${JOB_NAME} ${BUILD_DISPLAY_NAME} : ${BUILD_URL} + + Console output: ${BUILD_URL}console + """ + for(emailto in emailtolist) { + mail( + subject: "[Jenkins] Failed build: ${JOB_NAME} ${BUILD_DISPLAY_NAME}", + body: emailbody, + to: emailto + ) + echo "Send email to: ${emailto}" + } } } @@ -220,9 +224,8 @@ def performFailedBuildActions() { } } if (postbuildactions) { - def emailtolist = postbuildactions['Email']['To'] - if (emailtolist) { - sendemails(emailtolist) + if (postbuildactions['Email']) { + sendemails(postbuildactions['Email']) } if (postbuildactions['ExtEmail']) { sendextemail(postbuildactions['ExtEmail'])