Responding to application events

Using the Atlassian Event framework and the plugin system, Stash makes it easy to respond to events such as projects being created, removed and repositories being pushed or pulled from.

How to respond to events

  1. Create a Java class called MyEventListener.
  2. Create a new method called myListener that takes a single event (In our example, RepositoryPushEvent) as an argument and annotate it with EventListener. This annotation tells the event framework that the method is listening for the specified type of event.
  3. Add a component to your atlassian-plugin.xml for the MyEventListener class to register it with the plugin framework.
  4. Implement the myListener method to respond to the event however you like.


package com.atlassian.stash.example;

import com.atlassian.event.api.EventListener;

public class MyEventListener
	public void mylistener(RepositoryPushEvent pushEvent)
		log.logger("A push was made to " + pushEvent.getRepository()); //Whenever a push is made, the RepositoryPushEvent is fired and this listener is called


<component key="MyEventListener" class="com.atlassian.stash.example.MyEventListener"/>

Asynchronous events

Any event marked with the @AsynchronousPreferred annotation is likely to be executed on a pool thread, so any code subscribing to these events should be thread safe.

Available events

All events fired by Stash core live in com.atlassian.stash.event and it's child packages (see for example com.atlassian.stash.event.pull and com.atlassian.stash.event.permission).

Please grab the source or browse the javadoc for a full listing of available event classes.