How to configure Event listeners for plan branch creation in Bamboo
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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:
1 2 3 4 5 6 7 8 9 10 11
@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.,
1 2
<bambooEventListener key="environmentDependencyListener" class="com.test.MyListener"/>
Was this helpful?