New to JIRA Development, Need Some Help

Hi all,

This is my first post in Atlassian Dev!

I’m working on creating my own Jira Plugin that takes action once a user does something like update an issue. Where I’m running into issues is actually reacting to that event. I’ve read all the documentation I can find, and the tutorial surrounding this type of development was posted 2 years ago and I had to use multiple workarounds just to follow it. I’m at the point where I’ve found that com.atlassian.jira.event.issue.IssueEvent is where I should be looking. But I’m still unfamiliar with how to actually react to this event, and how to get info surrounding that event.

Any help would be greatly appreciated!

The interesting portions of the code example are:

  • The actual Listener class: Bitbucket
  • The pom.xml file, which handles dependencies: Bitbucket

The short path here is as follows.

Add a dependency on Spring Framework for the lifecycle events (to “register” and “unregister” your Listener as your plugin comes and goes).

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.6.RELEASE</version>
            <scope>provided</scope>
        </dependency>

Write a listener that Injects EventPublisher, Implements DisposableBean/InitializingBean and override the methods with the eventPublisher.register(this) bit. Then write a method annotated with @EventListener that does what you want.

@EventListener
    public void onIssueEvent(IssueEvent issueEvent) {
        Long eventTypeId = issueEvent.getEventTypeId();
        Issue issue = issueEvent.getIssue();

        if (eventTypeId.equals(EventType.ISSUE_CREATED_ID)) {
            log.info("Issue {} has been created at {}.", issue.getKey(), issue.getCreated());
        } else if (eventTypeId.equals(EventType.ISSUE_RESOLVED_ID)) {
            log.info("Issue {} has been resolved at {}.", issue.getKey(), issue.getResolutionDate());
        } else if (eventTypeId.equals(EventType.ISSUE_CLOSED_ID)) {
            log.info("Issue {} has been closed at {}.", issue.getKey(), issue.getUpdated());
        }
    }
2 Likes