Search code examples
jenkinsjenkins-pipelinejenkins-plugins

How to add "default recipients" ($DEFAULT_RECIPIENTS) to recipientProviders in Jenkins EmailExt?


I am using Jenkins and Emailext plugin for emailing. Here is a test pipeline, which works fine:

pipeline
{
  agent any

  stages
  {
    stage ('Start')
    {
      steps
      {
        echo 'Hello'
        // error('Abort to test failure.')
      }
    }
  }

  post
  {
    success
    {
      emailext (
          subject: '$DEFAULT_SUBJECT',
          body: '$DEFAULT_CONTENT',
          recipientProviders: [ requestor(), ? ]
        )
    }

    failure
    {
      emailext (
          subject: '$DEFAULT_SUBJECT',
          body: '$DEFAULT_CONTENT',
          recipientProviders: [developers(), requestor(), culprits()]
        )
    }
  }
}

I would like to send success emails to requestor and to "default recipients" which I specified under Manage Jenkins -> Configure System -> Extended E-mail Notification.

How do I add "default recipients" ($DEFAULT_RECIPIENTS) to recipientProviders?


Solution

  • Try like this:

    success
        {
          emailext (
              subject: '$DEFAULT_SUBJECT',
              body: '$DEFAULT_CONTENT',
              to: '$DEFAULT_RECIPIENTS',
              recipientProviders: [ requestor() ]
            )
        }
    

    recipientProviders parameter is used to add additional recipients.

    This will send the email to both recipientProviders and DEFAULT_RECIPIENTS whenever job is success.