Filter culprits on email-ext

158 views
Skip to first unread message

Jon Schewe

unread,
Apr 1, 2014, 5:56:40 PM4/1/14
to jenkinsci-users
I use the email-ext plugin to send out emails about build failures. I originally had it set to send email to all culprits when the build failed. However I import some code from other repositories and then Jenkins wanted to send emails to people that weren't on my development team because of these imports. Is there a way to tell email-ext to only send email to a particular domain when picking the culprits?

Slide

unread,
Apr 1, 2014, 5:58:14 PM4/1/14
to Jenkins User Mailing List
No, culprits comes from Jenkins itself. The best you could do is have a presend script that modifies the MimeMessage's To list.


--
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.



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

Jon Schewe

unread,
Apr 1, 2014, 6:14:34 PM4/1/14
to jenkinsci-users
Which would need some custom Java code, correct?

Is there another plugin that might work?

Slide

unread,
Apr 1, 2014, 6:23:58 PM4/1/14
to Jenkins User Mailing List
No, you use Groovy for the pre-send script. There is no other plugin that I know of.

Jon Schewe

unread,
Apr 4, 2014, 3:31:42 PM4/4/14
to jenkinsci-users
Oh, that doesn't sound too bad. Can you point me at some documentation and/or examples?

Thanks.

Slide

unread,
Apr 4, 2014, 4:09:53 PM4/4/14
to Jenkins User Mailing List
Information from the wiki [1]

Pre-send Script

The pre-send script is a feature which allows you to write a script that can modify the MimeMessage object prior to sending. This would allow adding custom headers, modifying the body, etc. Predefined variables include:

  • msg - the MimeMessage object which can be modified
  • logger - a PrintStream and will write to the job's log. 
  • build - the build this message belongs to
  • cancel - a boolean, which when set to true will cancel the sending of the email
so something like this:

recipients = msg.getRecipients(Message.RecipientType.TO)
filtered = recipients.findAll { addr -> !addr.toString().contains('@baddomain.com') }
msg.setRecipients(Message.RecipientType.TO, filtered)

slide


Jon Schewe

unread,
Apr 4, 2014, 7:31:14 PM4/4/14
to jenkinsci-users
Awesome, thanks!

Jon Schewe

unread,
Apr 14, 2014, 12:04:19 PM4/14/14
to jenkinsci-users
For those that might want to do this themselves. I wanted to only send to gooddomain.com and not send anywhere else. Here is the script that worked. 

recipients = msg.getRecipients(javax.mail.Message.RecipientType.TO)
filtered = recipients.findAll { addr -> addr.toString().contains('@gooddomain.com') }
msg.setRecipients(javax.mail.Message.RecipientType.TO, filtered as javax.mail.Address[])

Slide

unread,
Apr 14, 2014, 12:28:39 PM4/14/14
to Jenkins User Mailing List
I added it to the Email-ext Recipes [1] page I created on the wiki.

slide

Reply all
Reply to author
Forward
0 new messages