15

In Jenkins pipeline I'm using email-ext 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. admin@myshop.com, 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 'admin@myshop.com' with emailextrecipients?

Mike
  • 14,010
  • 29
  • 101
  • 161
Generic Ratzlaugh
  • 717
  • 1
  • 6
  • 13

2 Answers2

27

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:

emailext(
    subject: email_subject,
    mimetype: 'text/html',
    to: 'admin@myshop.com',
    recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']],
    body: email_body
)
Mike
  • 14,010
  • 29
  • 101
  • 161
Generic Ratzlaugh
  • 717
  • 1
  • 6
  • 13
10

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

def recipientProviders = [];
recipientProviders.add([$class: 'CulpritsRecipientProvider']);
recipientProviders.add([$class: 'DevelopersRecipientProvider']);
recipientProviders.add([$class: 'RequesterRecipientProvider']);

emailext(
    subject: email_subject,
    mimetype: 'text/html',
    to: 'admin@myshop.com',
    recipientProviders: recipientProviders,
    body: email_body
)
Mike
  • 14,010
  • 29
  • 101
  • 161
vezun
  • 103
  • 2
  • 5