Search code examples
templatesjenkinsemail-ext

Is it possible to customize the subject of an email-ext generated email based on the build that finished


I know you can use a few tokens to customize the subject of the email, but I am looking for something a little more dynamic. I was hoping I could set an environment variable or write to a file somewhere from my build script, and have email-ext use that when formatting its email subject.

Is there anything available that might allow this?

Thanks for the help


Solution

  • You can modify the email subject using a pre-send groovy script as well.

    For example, the following script checks for certain conditions and prepends some text on the subject line:

    boolean isClaimed = false;
    build.actions.each { action ->
       if(action.class.name == "hudson.plugins.claim.ClaimBuildAction" 
          && action.isClaimed()) {
           isClaimed = true;
           hudson.model.User user = hudson.model.User.get(action.getClaimedBy()); 
           logger.println("[addClaimerOrCulprits.groovy] Build is claimed by " + user);
           logger.println("[addClaimerOrCulprits.groovy] Sending email to claimer");
           address = user.getProperty(hudson.tasks.Mailer.UserProperty).getAddress() ; 
           msg.addRecipients(javax.mail.Message.RecipientType.TO, address ); 
           msg.setSubject("Attn " + action.getClaimedBy() + ": " + msg.getSubject());
       }
    }