How to configure Event listeners for plan branch creation in Bamboo
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"/>