Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins pipeline emailext emailextrecipients: Can I also add specific, individual email address?

In Jenkins pipeline I'm using emailext with emailextrecipients as follows:

emailext (
    subject: email_subject, 
    mimetype: 'text/html', 
    to: emailextrecipients([[$class: 'CulpritsRecipientProvider'],[$class: 'RequesterRecipientProvider']]), 
    body: email_body
    )

And I want to add a specific email address (e.g. [email protected]) to the list generated using emailextrecipients. I want that addressee (me or a manager or admin) to always get the email, but the addressee might be a culprit or requester and I don't want emailext to send two emails to that addressee.

Is there a way to merge '[email protected]' with emailextrecipients?

like image 285
Generic Ratzlaugh Avatar asked Apr 18 '17 13:04

Generic Ratzlaugh


People also ask

How do I add a recipient list in Jenkins?

Enter the recipient email id in the 'E-mail Notification' box and select the checkbox next to the 'Send e-mail for every unstable build' option. Click the 'Advance Settings…' button in the 'Editable Email Notification' box. Click the 'Add Trigger' drop-down and select the 'Always' option and Click the 'Save' button.

In which other areas does the extended email plugin provide customization?

It provides customization of three areas: Triggers. Select the conditions that should cause an email notification to be sent. Content.

What is DevelopersRecipientProvider?

[[$class: 'DevelopersRecipientProvider']] is a list of map, 'recipientProviders' is the key same as 'subject' or 'body' . You may think the emailext is a method with signature: void emailext(Map<String, Object> map) 3) emailext is a method implemented in Java. You can find source code here and here.


2 Answers

A slight variation to Generic Ratzlaugh's answer, in case you need to use conditional logic for email destinations.

def myProviders = [ [$class: 'CulpritsRecipientProvider'], [$class: 'DevelopersRecipientProvider'] ];

myProviders.add ( [$class: 'RequesterRecipientProvider'] );

emailext (
    subject: email_subject, 
    mimetype: 'text/html', 
    to: '[email protected]',
    recipientProviders: myProviders, 
    body: email_body
    )
like image 152
sterdun Avatar answered Nov 16 '22 04:11

sterdun


I don't know how I missed this, but the answer is in the email-ext doc. Use the to: for the additional email addresses, and use recipientProviders: instead of to: emailextrecipients. So one would have:

emailext (
    subject: email_subject, 
    mimetype: 'text/html', 
    to: '[email protected]',
    recipientProviders: [[$class: 'CulpritsRecipientProvider'],[$class: 'RequesterRecipientProvider']], 
    body: email_body
    )
like image 22
Generic Ratzlaugh Avatar answered Nov 16 '22 03:11

Generic Ratzlaugh