Any way to affect the recipient of the mail(ext) plugin recipient list ?

329 views
Skip to first unread message

Max Rydahl Andersen

unread,
Mar 31, 2014, 2:16:41 AM3/31/14
to jenkins...@googlegroups.com
Hey,

Background:
I got a little script (https://github.com/maxandersen/jiralint) which is used to take queries against Jira locating stale jiras or jiras with missing/wrong information on them
and then generate a junit test xml report which then in turn makes jenkins generate a build failure report. Been working great for years but until now
even I can identifiy the individuals who needs to react for now the build failure just been blasted out to the whole team.

I would like to change/fix that.

Question:
Is it possible by the build itself to change the recipients of the mail(ext) plugin ?

a) either by using an environment variable
b) contributing to the list of culprits

For #A I've only seen it allow build paramters - that is not enough since I don't know the set of recipients before the build have completed.
For #B I've only found a way to change that is to implement a fork of the git plugin but I would prefer I could simply add/change the list of culprits if possible.

Any ideas/suggestions to the above that does not require *too* exotic plugins ? :)

Thanks,
/max

Max Rydahl Andersen

unread,
Mar 31, 2014, 4:24:33 AM3/31/14
to jenkins...@googlegroups.com
I found this issue: https://issues.jenkins-ci.org/browse/JENKINS-5942

it was closed as incomplete but as far as I can see it is exactly the problem - not possible to access environment variables set by the build in the actual mail.

Slide

unread,
Mar 31, 2014, 8:56:11 AM3/31/14
to Jenkins User Mailing List

Environment variables work fine, you use the ENV token like ${ENV, var="YOURVAR"}. You could also use a presend script to modify the recipient list using a groovy script. See the wiki for more info.

--
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/d/optout.

Max Rydahl Andersen

unread,
Apr 1, 2014, 7:42:55 AM4/1/14
to jenkins...@googlegroups.com


On Monday, March 31, 2014 2:56:11 PM UTC+2, slide wrote:

Environment variables work fine, you use the ENV token like ${ENV, var="YOURVAR"}. You could also use a presend script to modify the recipient list using a groovy script. See the wiki for more info.


No, the ${ENV style does not work in the body nor recipient list.

I guess I could try the groovy script approach - but would be simpler if mail-ext actually supported the env variables as claimed. Maybe it was added very late and I don't have latest update ?

/max

Slide

unread,
Apr 1, 2014, 7:50:47 AM4/1/14
to Jenkins User Mailing List

No, its been around for a long time and works for me just fine. It may depend on how you are setting the env variable. Ones that are set by build steps are not retained by Jenkins (nothing to do with email-ext) so keep that in mind.

Max Rydahl Andersen

unread,
May 13, 2014, 2:34:47 AM5/13/14
to jenkins...@googlegroups.com


On Tuesday, April 1, 2014 1:50:47 PM UTC+2, slide wrote:

No, its been around for a long time and works for me just fine. It may depend on how you are setting the env variable. Ones that are set by build steps are not retained by Jenkins (nothing to do with email-ext) so keep that in mind.


so this means there is no way for the build to affect the list of recipients of mail ?

I tried using tokens but they seem to only work for subject and body.

Is this somehow intentional ?

/max

Max Rydahl Andersen

unread,
May 13, 2014, 3:48:18 AM5/13/14
to jenkins...@googlegroups.com
I take this back.

${FILE,path="PATH"} worked. Environment variables does not.

I've updated https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin to actually state recipient list also honors email tokens.

 

busie...@gmail.com

unread,
Feb 24, 2016, 7:14:05 AM2/24/16
to Jenkins Users
Hi
I'm trying to add pre-send script and modify the recipients list using groovy just like you mentioned , but I can't find relevant wiki for this. Where I can see the API I can use inside the script.
only saw examples using 'build' and using 'User' APIs. is there any build.Recipients = /***/ ?

thanks in advance

Slide

unread,
Feb 24, 2016, 7:46:07 AM2/24/16
to Jenkins Users
There is a 'msg' object that is an instance of MimeMessage [1]. The 'build' object is an AbstractBuild [2] instance. To modify the recipients, you would want to do stuff with the 'msg' object.



geoffroy...@gmail.com

unread,
Feb 24, 2016, 11:19:41 AM2/24/16
to Jenkins Users
Hello
we use this script in the presend part of EmailExt plugin. It will change the sender email address, if an environment variable is set.
I think you can easily adapt it to your needs

import javax.mail.Message.RecipientType
import javax.mail.Address
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeMessage
if ("${ENV,var="PROJECT_ADMIN_MAIL"}") {
    msg.setFrom(new InternetAddress("${ENV,var="PROJECT_ADMIN_MAIL"}"))
}
Reply all
Reply to author
Forward
0 new messages