Email-ext plugin - dynamically modifying the recipient list

1,314 views
Skip to first unread message

Bob Bick

unread,
Jun 10, 2013, 11:50:17 AM6/10/13
to jenkins...@googlegroups.com

Hi,

 

We are using the Email-ext plugin 2.24.1 to send out email notifications. Overall, it works great; however, I was given a new requirement:

 

·         Send out email notifications to a list of users if the build is a “release build”. More specifically, there is a Boolean RELEASE_BUILD Job parameter that controls whether the build is a “release build” and there is a RELEASE_BUILD_EMAIL_DISTRIBUTION parameter that contains a list of users. If the RELEASE_BUILD Job parameter is “true”, then RELEASE_BUILD_EMAIL_DISTRIBUTION users should also receive the email notification.

 

I tried to use the Pre-send Script to change the recipient list dynamically. However, the Pre-send Script does not get invoked if there are no recipients.

 

My “brute force” solution was to put a dummy email account as the recipient (so that the Pre-send Script would always get invoked); and then use the Pre-send Script to change the recipient list dynamically. But, I really don’t like this hacked solution since emails are always being sent to a dummy email account.

 

Q. Has anyone else ever had a similar requirement? If so, did you find a better solution?

 

Thanks in advance,

 

Bob


*** *** ***
This message contains information which may be confidential and privileged. Unless you are the addressee (or authorized to receive for the addressee), you may not use, copy or disclose to anyone the message or any information contained in the message. If you have received the message in error,  please advise the sender by reply e-mail and delete the message.

Slide

unread,
Jun 10, 2013, 11:51:40 AM6/10/13
to jenkins...@googlegroups.com
The email-ext plugin will check if the recipient list is empty before trying to send the email (which is where the pre-send script is executed). Putting a dummy address in is currently the only way you would be able to achieve what you want to do.


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Website: http://earl-of-code.com

Bob Bick

unread,
Jun 10, 2013, 11:54:35 AM6/10/13
to jenkins...@googlegroups.com

Thanks for the quick response. I was afraid that that was the only solution L

Slide

unread,
Jun 10, 2013, 12:17:51 PM6/10/13
to jenkins...@googlegroups.com
You can always file a JIRA on it, I am not sure of the mechanics of changing the location of the execution of the pre-send script since I can't look at the code right now, but its something that could possibly be changed.

Louis Roché

unread,
Jun 11, 2013, 3:38:46 AM6/11/13
to jenkins...@googlegroups.com, bb...@netjets.com
Hi.

You can use a groovy template in the recipients list to modifying the recipients list. The last line of your script should return a string with all the recipients.
For examples, you can have a file recipients.template:

<%
def authors = "m...@example.tld"

if (build.environment["RELEASE_BUILD"]) {
    authors = build.environment["RELEASE_BUILD_EMAIL_DISTRIBUTION"]
}
%>

${authors}

The recipients should be comma separated.

And in your jobs configuration, in the recipients list, you put ${SCRIPT, template="recipients.template"}

Louis

Slide

unread,
Jun 11, 2013, 8:42:10 AM6/11/13
to jenkins...@googlegroups.com

You can also just use a groovy script, ${SCRIPT, script="yourscript.groovy"}

--
Reply all
Reply to author
Forward
0 new messages