Listeners

Using Listeners in ScriptRunner for Bamboo, you can perform custom actions whenever standard Bamboo system events are fired. There are built-in listeners, or you can create a custom listener.

Adding a Listener

  1. Navigate to Admin > Listeners.

  2. Select the Add New Item button to expand the listeners available to create.

  3. Choose a Custom Listener or a built-in listener.

Custom Listeners

You can create custom listeners with your own scripts. To add a custom listener, follow these steps:

  1. Select Custom Listener.
    custom event handler form

  2. In the Events field, select the events you want to listen for.

    The event is contained in the script binding. The event object has the type corresponding to its name. For example, if you are listening for BuildCompletedEvent you get a BuildCompletedEvent object.

    You may choose to have your listener look for multiple events. If you need to do different things depending on the type of event, you can check that with instanceof.

    Alternatively, you can type your event to the most specific superclass. In in the above example that would be BuildEvent.

    For example, to get the page content for bothBuildCompletedEventandBuildDeletedEvent:


    def event = event as BuildEvent// <1>
    def content = event.content.bodyAsString
    
    // do something with the page content

    In the first line, the event is passed in the binding. This line is only used to give type information when using an IDE, and has no functional impact.