How to limit notifications for automation actions

Often it is desirable to have automation perform actions that do not cause notifications to be sent that normally would be. Some examples are:

  • Changing an issue multiple times in a sequence of updates
  • Updating a field on a regular basis

Unfortunately, the notification schemes don't have an option regarding the originator of the request. Here is what can be done:

Instructions

  1. Create a user id (for example: automation2) that is only to be used for changes that do not cause notifications
  2. Unzip custom-mail-listener.zip
  3. Get the source for the MailListener.java code from the JIRA source code for your version of JIRA
    • Normally found in .../jira/src/java/com/atlassian/jira/event/listeners/mail
  4. Add it to the source directory in the correct location (replacing the stub)
  5. Modify it to be something like:

        protected void sendNotification(IssueEvent event) {
            if (event.isSendMail()) {
                if (log.isDebugEnabled()) {
                    log.debug("Event user: " + event.getRemoteUser().getName());
                }
    
                if (!("automation2".equals(event.getRemoteUser().getName()))) {
                    GenericValue projectGV = event.getIssue().getProject();
                    GenericValue notificationScheme = notificationSchemeManager.getNotificationSchemeForProject(projectGV);
    
                    if (notificationScheme != null) {
                        createMailItems(notificationScheme, event);
                    }
                } else if (log.isDebugEnabled()) {
                    log.debug("Ignore sending notification for event by user: " + event.getRemoteUser().getName());
                }
            }
        }
    
  6. Install the Atlassian SDK
  7. From the directory you created with the unzip, run atlas-mvn compile
  8. Copy the generated class file to your JIRA installation
    • Look in .../atlassian-jira/WEB-INF/classes/com/atlassian/jira/event/listeners/mail
    • Copy the shipped version somewhere for back
    • Replace with your compiled version
  9. Restart JIRA
  10. Use on your automation CLI command:

    java -jar .../atlassian-cli/release/jira-cli-x.x.x.jar --user automation2 ...
    

Built Classes

Here are classes that have already been built using automation2 as the name for specific JIRA releases. You will need to rename the class to MailListener.class

  File Modified

File MailListener-4.0.1.class

Mar 04, 2010 by Bob Swift

File MailListener-4.4.4.class

Aug 20, 2012 by Bob Swift