Documentation for JIRA 6.4 (This documentation includes the project navigation sidebar). Not using this? See below:
(JIRA 6.4 without sidebar documentation | JIRA 6.3.x documentation | JIRA Cloud documentation | earlier versions of JIRA)

Skip to end of metadata
Go to start of metadata

Listeners are unique to JIRA, and a very powerful way to extend it.

JIRA has a complete event subsystem which fires events whenever anything happens inside the application. For example an ISSUE_CREATED event is fired whenever an issue is created.

A Listener is a class that implements one of the Listener interfaces. It is then called whenever events occur in JIRA. Using those events, you can then perform any action you want. For example the email sent by JIRA is driven by the MailListener.

Listeners are most useful when you want to drive or affect external systems from events which occur within JIRA.

On this page:

Listener Interfaces

JIRA has the following concrete Listeners (which extend the base JiraListener interface):

com.atlassian.jira.event.JiraListener

The base interface which all other JIRA listener interfaces extend. Covers core listener properties like uniqueness, description, parameters etc.
API doc

com.atlassian.jira.event.issue.IssueEventListener

The main listener interface in JIRA, used whenever anything happens to an issue.
API doc

com.atlassian.jira.event.user.UserEventListener

This listener is called whenever anything happens to a user within JIRA.
API doc

Example Listeners

The examples provided may be freely used and modified for use in your own environment. The source of all examples is available and should give you good overview of how simple it is to write your own listeners. Both example listeners are included with JIRA 2.1, and both implement UserEventListener and IssueEventListener.

  • DebugListener (source) — This is a very simple listener that prints events and their content to System.out whenever they are received. To test this listener, add a listener with the class com.atlassian.jira.event.listeners.DebugListener .
  • MailListener (source) — This listener is how mail notifications are currently sent from within JIRA, and a good example of a more complex listener. It basically listens for events, and turns them into email notifications using Velocity templates to generate the mail bodies.
    This listener is usually always turned on in JIRA — see Email Notifications for more details. If you want to write more complex or more specific notifications, you can disable the internal MailListener and add your own.

Other examples of useful tasks that can be accomplished with listeners are:

  • Send SMS or IM notifications — A listener could easily send notifications for various events via SMS or instant messenger (e.g. ICQ or AIM) - or anywhere that you have a Java library to send messages.
  • Group notifications — A listener could notify certain groups of issue changes, depending on the content of the issue. For example any issue containing "windows" in the environment could notify your "windows-developers" group.

Registering a Listener

For custom-written listener classes, make sure your listener class is in the classpath where JIRA can see it — the best locations are usually the <jira-application-dir>/WEB-INF/classes or <jira-application-dir>/WEB-INF/lib subdirectories within of your JIRA Installation Directory (as JAR files).

To register a listener:

  1. Log in as a user with the 'JIRA System Administrators' global permission.
  2. Choose > System. Select Advanced > Listeners to open the Listeners page.
    Keyboard shortcut: 'g' + 'g' + type 'lis'
  3. In the 'Add Listener' form at the bottom of the page, complete the following fields:
    • 'Name' — an appropriately descriptive name for the listener.
    • 'Class' — the fully-qualified class name of your listener.

      To use one of JIRA's built-in listener classes, first click the 'Built-in Listeners' link to expand the list of listener classes and then click the name of the specific class in the list. The fully-qualified class name of the built-in listener will be added to the 'Class' field.
  4. Click the 'Add' button and the listener will now be added to the list of listeners above.

Editing Listener Properties

If your listener accepts parameters or properties, you can edit these by clicking the 'Edit' link associated with your listener (on the 'Listeners' page in JIRA's Administration area).

When defining your own Listener, there is a method getAcceptedParams to overload for defining the parameter names which are passed as an array of String objects. The init method is given a Map with the configured values (the JavaDoc is outdated). The com.atlassian.jira.event.listeners.DebugParamListener class is a good example of doing this with two parameters.

Removing a Listener

To remove a listener, click the 'Delete' link associated with that listener (on the 'Listeners' page in JIRA's Administration area).

Custom Events

With the ability to add custom events to JIRA, the Listener must be updated to deal with the event as appropriate. This is possible by providing an implementation for the method customEvent(IssueEvent event) in the Listener. For example, the MailListener implementation passes the custom event on for notification processing. The DebugListener logs that the custom event has been fired.

See Also
{"cc_re__cc_re__cc_by_2_5_au": ["ias=\"btn_docs.png\" data-base-url=\"https://confluence.atlassian.com\" data-linked-resource-content-type=\"image/png\" data-linked-resource-container-id=\"222724425\" data-linked-resource-container-version=\"11\" title=\"btn_docs.png\"></span></a></p></div></div></div></div>\n<div class=\"sectionColumnWrapper\"><div class=\"sectionMacro\"><div class=\"sectionMacroRow\"><div class=\"columnMacro\" style=\"width:900px;min-width:900px;max-width:900px;\"><p style=\"text-align: center;\">\u00a0</p><p style=\"text-align: center;\"><a href=\"http://creativecommons.org/licenses/by/2.5/au/\" class=\"external-link\" rel=\"nofollow\"><span class=\"confluence-embedded-file-wrapper\"><img class=\"confluence-embedded-image\" src=\"/download/attachments/180295777/ico_cc.png?version=1&amp;modificationDate=1256506275108&amp;api=v2\" data-image-src=\"/download/attachments/180295777/ico_cc.png?version=1&amp;modificationDate=1256506275108&amp;api=v2\" data-unresolved-comment-count=\"0\" data-linked-resource-id=\"204341738\" data-linked-resource-version=\"1\" data-linked-resource-type=\"attachment\" data-linked-resource-default-alias=\"ico_cc.png\" dat", "dificationDate=1256506275108&amp;api=v2\" data-unresolved-comment-count=\"0\" data-linked-resource-id=\"204341738\" data-linked-resource-version=\"1\" data-linked-resource-type=\"attachment\" data-linked-resource-default-alias=\"ico_cc.png\" data-base-url=\"https://confluence.atlassian.com\" data-linked-resource-content-type=\"image/png\" data-linked-resource-container-id=\"180295777\" data-linked-resource-container-version=\"39\"></span></a> Except where otherwise noted, content in this space is licensed under a <a href=\"http://creativecommons.org/licenses/by/2.5/au/\" class=\"external-link\" rel=\"nofollow\">Creative Commons Attribution 2.5 Australia License</a>.</p><p style=\"text-align: center;\">\u00a0</p></div></div></div></div>\n        </div>\n    \n    </div>\n</div>\n\n\n        \n            \n\n<div id=\"footer\" role=\"contentinfo\">\n    <section class=\"footer-body\">\n\n                                        \n        \n\n        <ul id=\"poweredby\">\n            <li class=\"noprint\">Powered by <a href=\"http://www.atlassian.com/software/confluence\" class=\"hover-footer-link\">Atlassian Confluence</a> <span id='footer"]}