0

When a build job fails, I want to send an email to the user who started the job.

I use a jenkins buildfile (Pipeline script). The current code is:

     post {
          success {
              doSomething()
          }
          failure {
              step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'me@foo', sendToIndividuals: true])
          }
          changed {
              step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'me@foo', sendToIndividuals: true])
          }
      }

Sending the mail to me@foo "statically" (i.e. putting the address as in the code above) works well. So the Mailer plugin works well, but I cannot figure out how to make a reference to the user that started the job.

I tried out putting s.th. like the following at the recipients list, but it does not work: '${BUILD_USER_EMAIL}', $BUILD_USER_EMAIL

Thank you in advance for any hint to solve this.

gabolo
  • 21
  • 4
  • Hello @gabolo. Check this solution. Try method 3. https://stackoverflow.com/a/60440626/10363259 – vijay v Feb 03 '23 at 13:53
  • Does this answer your question? [How to get the BUILD\_USER in Jenkins when job triggered by timer?](https://stackoverflow.com/questions/36194316/how-to-get-the-build-user-in-jenkins-when-job-triggered-by-timer) – vijay v Feb 03 '23 at 13:54

1 Answers1

0

We identified the problem by ourselves: the plugin build user vars was not activated correctly. Now it works.

We use the following code:

pipeline {
  ...
  post {
    failure {
      step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${BUILD_USER_EMAIL}", sendToIndividuals: true])
    }
    changed {
      step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${BUILD_USER_EMAIL}", sendToIndividuals: true])
    }
  }
}

Thank you for your replies.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
gabolo
  • 21
  • 4