2

I'm using jenkins emailext plugin, in the Jenkins global configuration UI, under Extended E-mail Notification section, I can set Default Recipients to be a list of recipients.

My question is, inside my Jenkinsfile, when I use emailext() step, how can I reference Default Recipients set in the UI, because the to argument for the step only seems to take a String.

zanyman
  • 667
  • 2
  • 11
  • 22

1 Answers1

2

In the help message for the 'Default Recepients' options of the 'Extended E-mail Notification' plugin found in the Jenkins global configuration, one can find the not so clear statement:

Customize the default recipient list of the email notifications. The plugin will use this list if none is overridden in the project configuration. You may use the $DEFAULT_RECIPIENTS token in projects to include this default list, as well as add new addresses at the project level. To CC or BCC someone instead of putting them in the To list, add cc: or bcc: before the email address (e.g., cc:someone@example.com, bcc:bob@example.com).

Taking a best guess how this could work I gave the following a try - and it worked:

emailext body: '', to: '$DEFAULT_RECIPIENTS', subject: 'To default recepient list'

Be careful not to use double quotes for the to: argument as groovy would jump in and try to replace it with the value of a variable called DEFAULT_RECIPIENTS.

What apparently doesn't work is leaving out the to: arguments. It'll just say that the list of recipients is empty.

Joerg S
  • 4,730
  • 3
  • 24
  • 43
  • is there a way to set up multiple email list? it makes no sense to me why there is just one when different job may require different sets of emails. – mike01010 May 26 '23 at 00:18
  • You have different choices to whom to send those mails. Please check the extenden E-Mail notificiation plugin documentation: https://plugins.jenkins.io/email-ext/ The example above (and the question) was about how to use the default recipients as defined in the global Jenkins configuration. If you don't want the default, you can just use any DL as required. – Joerg S May 30 '23 at 15:11