How to configure Event listeners for plan branch creation in Bamboo

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

This document explains how to configure Event listeners in Bamboo for plan branch creation.

Environment

This applies to all supported versions of Bamboo supporting Event Listeners.

Solution

  • For plan branch creation event, you can use the EventListener com.atlassian.bamboo.event.ChainCreatedEvent.

  • The event contains only the plan key and is sent for both plans and plan branches.
  • So you first need to check if the event was sent for a plan or branch. You can use plan cache for that, something like:    

    @EventListener
        public void onChainCreatedEvent(final ChainCreatedEvent event) {
            final ImmutableChain chain = cachedPlanManager.getPlanByKey(event.getPlanKey(), ImmutableChain.class);
            if (chain == null || !chain.hasMaster() || !(chain instanceof ImmutableChainBranch)) {
                // the event was sent for plan, nothing to do here
                return;
            }
    
            final ImmutableChainBranch branch = (ImmutableChainBranch) chain;
            // you can now use the branch
        }
  • EventListeners need to be registered in atlassian-plugin.xml, for e.g.,

    <bambooEventListener key="environmentDependencyListener" 
    class="com.test.MyListener"/>


Last modified on Apr 29, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.