Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-12421

Add pre-send step to email-ext that can modify the mail message object

      When the Email-Ext plugin is used in conjunction with the Claim plugin there is no way to configure a project's email options to only send to the one who has claimed it. This results in every person on a team receiving emails for a build they did not break, turning Jenkins emails into something annoying instead of something useful. For someone who knew the code this would be a pretty easy feature to add. And while this would be a good feature, I think a more elaborate solution that would allow Email-ext plugin users to access/modify all parts of the email message (including who the message is being sent to) would be more useful in the long run. Giving users access to all parts of the email message and the option to run a Groovy script after the email has been built, but before the email has been sent would satisfy this feature request and would make the Email-Ext plugin much more versatile.

          [JENKINS-12421] Add pre-send step to email-ext that can modify the mail message object

          Alex Earl added a comment -

          I am planning on adding the groovy feature, I was just wondering where you might want to configure it. If only at the project level (not at the global level and not at the trigger level) it makes it a bit easier

          Alex Earl added a comment - I am planning on adding the groovy feature, I was just wondering where you might want to configure it. If only at the project level (not at the global level and not at the trigger level) it makes it a bit easier

          Code changed in jenkins
          User: Alex Earl
          Path:
          src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java
          src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherDescriptor.java
          src/main/resources/hudson/plugins/emailext/ExtendedEmailPublisher/config.jelly
          src/main/webapp/help/projectConfig/presendScript.html
          src/test/java/hudson/plugins/emailext/ExtendedEmailPublisherTest.java
          http://jenkins-ci.org/commit/email-ext-plugin/5fa24b49277c865e63148b40d109d3df7c1a5db0
          Log:
          Fix JENKINS-12421

          Implement pre-send script that allows modifying or cancelling the
          sending of the email.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Alex Earl Path: src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherDescriptor.java src/main/resources/hudson/plugins/emailext/ExtendedEmailPublisher/config.jelly src/main/webapp/help/projectConfig/presendScript.html src/test/java/hudson/plugins/emailext/ExtendedEmailPublisherTest.java http://jenkins-ci.org/commit/email-ext-plugin/5fa24b49277c865e63148b40d109d3df7c1a5db0 Log: Fix JENKINS-12421 Implement pre-send script that allows modifying or cancelling the sending of the email.

          Alex Earl added a comment -

          Implemented an area in the project config for specifying a pre-send script which can modify the email message and even cancel sending the email if desired.

          Alex Earl added a comment - Implemented an area in the project config for specifying a pre-send script which can modify the email message and even cancel sending the email if desired.

          Markus added a comment -

          terrylwesterhold, I'm trying to achieve the same goal (JENKINS-16861) but I'm struggling with the script. Do you have something you could share?

          Markus added a comment - terrylwesterhold , I'm trying to achieve the same goal ( JENKINS-16861 ) but I'm struggling with the script. Do you have something you could share?

          Chris Nogradi added a comment -

          Looks like you mostly had it in the comments for Jenkins-16861. Here is what we use:

          build.actions.each { action ->
          if(action.class.name == "hudson.plugins.claim.ClaimBuildAction" && action.isClaimed())

          { logger.println(action.getClaimedBy()); hudson.model.User user = hudson.model.User.get(action.getClaimedBy()); address = user.getProperty(hudson.tasks.Mailer.UserProperty).getAddress() ; logger.println("Sending to " + address ); msg.setRecipients(javax.mail.Message.RecipientType.TO, address ); }

          }

          Note that we use the LDAP plugin to talk to ActiveDirectory.

          Chris Nogradi added a comment - Looks like you mostly had it in the comments for Jenkins-16861. Here is what we use: build.actions.each { action -> if(action.class.name == "hudson.plugins.claim.ClaimBuildAction" && action.isClaimed()) { logger.println(action.getClaimedBy()); hudson.model.User user = hudson.model.User.get(action.getClaimedBy()); address = user.getProperty(hudson.tasks.Mailer.UserProperty).getAddress() ; logger.println("Sending to " + address ); msg.setRecipients(javax.mail.Message.RecipientType.TO, address ); } } Note that we use the LDAP plugin to talk to ActiveDirectory.

          Chris Nogradi added a comment -

          Oh and I suppose I should mention that we occasionally receive emails from Jenkins with the an email title specifying a project which is different from the body of the email so I think there is a bug in this code that is either caused by not locking a shared resource or a cache value is not flushed properly.

          Chris Nogradi added a comment - Oh and I suppose I should mention that we occasionally receive emails from Jenkins with the an email title specifying a project which is different from the body of the email so I think there is a bug in this code that is either caused by not locking a shared resource or a cache value is not flushed properly.

          Alex Earl added a comment -

          Are you on the latest version of email-ext? I made some mods that should resolve this.

          Alex Earl added a comment - Are you on the latest version of email-ext? I made some mods that should resolve this.

          Chris Nogradi added a comment -

          Ah - yes we are - I'll keep an eye out and report if we observe it again.

          Chris Nogradi added a comment - Ah - yes we are - I'll keep an eye out and report if we observe it again.

          Alex Earl added a comment -

          There is already a jira filed by Xavier Nodet.

          Alex Earl added a comment - There is already a jira filed by Xavier Nodet.

          Markus added a comment -

          Thank you very much, Chris. Your script works perfectly!

          Markus added a comment - Thank you very much, Chris. Your script works perfectly!

            slide_o_mix Alex Earl
            terrylwesterhold terryl westerhold
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: