ChainCompletedEvent does not show branchName and other bamboo default env values

Dear Atlassian. We have bamboo7.1.4/bitbucket7.8.0 integrated . We implemented bamboo Event listener with java to do additional steps in separate system after the build has finished.
We decided to use ChainCompletedEvent because we want to trigger our additional steps (in different system) when all stages (build, unit test, other tests etc) finished.

@EventListener
public void myChainCompletedEvent(ChainCompletedEvent event) {
LOGGER.error("@@DEBUG myChainCompletedEvent.event.getChainExecution().isSuccessful()"+event.getChainExecution().isSuccessful());
LOGGER.error("@@DEBUG myChainCompletedEvent.getBuildContext"+event.getBuildContext());
LOGGER.error("@@DEBUG myChainCompletedEvent.event.getBuildContext().getCurrentResult().getCustomBuildData()"+event.getBuildContext().getCurrentResult().getCustomBuildData());
LOGGER.error("@@DEBUG myChainCompletedEvent.getPlanKey().getKey().toLowerCase()"+event.getPlanKey().getKey().toLowerCase());

if (event.getChainExecution().isSuccessful()) {
BuildContext buildContext = event.getBuildContext();
Map<String, String> customBuildData = buildContext.getCurrentResult().getCustomBuildData();
int buildNumber = buildContext.getBuildNumber();
if (acceptedToTest(event.getPlanKey().getKey().toLowerCase())) {
String branchName = customBuildData.get("planRepository.branchName");
String prKey = customBuildData.get("repository.pr.key");
String branchRevision = customBuildData.get("planRepository.revision");
String repositoryUrl = customBuildData.get("planRepository.repositoryUrl");
LOGGER.error("@@DEBUG myChainCompletedEvent..generic..planRepository.branchName"+branchName);
LOGGER.error("@@DEBUG myChainCompletedEvent..generic..repository.pr.key"+prKey);
LOGGER.error("@@DEBUG myChainCompletedEvent..generic..planRepository.revision"+branchRevision);
LOGGER.error("@@DEBUG myChainCompletedEvent..generic..planRepository.repositoryUrl"+repositoryUrl);

}
}
}

it worked well for most of the repositories but it does not work in 1,2 others.
Unfortunately we run into a bug which we cannot address/solve…

Our problem is that event hough bamboo is linked with Bitbucket we don’t get Bamboo variables | Bamboo Server 8.1 | Atlassian Documentation (eg planRepository.branchName) in buildContext.getCurrentResult().getCustomBuildData(). In fact it only contains plan.storageTag

Note#1 - Not sure if it’s related but this value exactly what I see in the metadata tag of the plan’s build.

Note#2 - when I check the inner job’s (DefaultStage/DefaultJob) metadata tag of the same plan I can see all expected values.

Note#3 - If I change the java code and the event listener to BuildFinishedEvent then these values are present in the buildContext.

Note#4 - However the other bitbucket repositories which look very similar (=they also don’t show these values in Plan’s metadata tab) these default bamboo env variables Bamboo variables | Bamboo Server 8.1 | Atlassian Documentation are passed correctly and I can access them in the ChainFinishedEvenHandler

Note#5 there are some default bamboo env variables which are always null (bamboo.repository.pr.key) for all repositories.

If there is a repository which does not pass this data in the ChainEventHandler it will stay like that. I was unable to modify the build plan to make it visible.

If there is a repository which does pass this data then in the ChainEventHandler it will also stay like that. I cannot modify the build plan in any way to make it disappear.

There seems to be no explanation for what is controlling if these “default” env variables will eventually be present in buildContext.getCurrentResult().getCustomBuildData() of the ChainFinished event handler.

I hope you can help us identifying the problem or by fixing a bug on your side.

I can see these both type of outputs in logs:


---> Logs for one repository/buildplan where branchName is null
2022-01-19 12:02:57,845 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-9] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent.event.getChainExecution().isSuccessful()true
2022-01-19 12:02:57,845 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-9] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent.getBuildContextcom.atlassian.bamboo.v2.build.BuildContextImpl@87d071e0
2022-01-19 12:02:57,845 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-9] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent.event.getBuildContext().getCurrentResult().getCustomBuildData(){dependenciesDisabled=false, plan.storageTag=plan-93882661}
2022-01-19 12:02:57,845 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-9] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent.getPlanKey().getKey().toLowerCase()rtb-dacas
2022-01-19 12:02:57,845 INFO [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-5] [DependencyChainListener] Checking children plans of [RTB-DACAS] for plan RTB-DACAS-405
2022-01-19 12:02:57,845 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-9] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent..generic..planRepository.branchNamenull
2022-01-19 12:02:57,845 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-9] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent..generic..repository.pr.keynull
2022-01-19 12:02:57,845 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-9] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent..generic..planRepository.revisionnull
2022-01-19 12:02:57,845 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-9] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent..generic..planRepository.repositoryUrlnull
2022-01-19 12:02:57,848 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-9] [AsynchronousAbleEventDispatcher] There was an ex

---> Logs for another repository/buildplan where branchName is not null
08:08,607 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-15] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent.event.getChainExecution().isSuccessful()true
2022-01-19 12:08:08,607 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-15] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent.getBuildContextcom.atlassian.bamboo.v2.build.BuildContextImpl@b3cc1d18
2022-01-19 12:08:08,607 INFO [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-10] [DependencyChainListener] Checking children plans of [RTB-SITE3303] for plan RTB-SITE3303-1
2022-01-19 12:08:08,607 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-15] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent.event.getBuildContext().getCurrentResult().getCustomBuildData(){planRepository.repositoryUrl=ssh://git@code.devrtb.com:7999/rtb/site.git, repository.675414082.git.repositoryUrl=ssh://git@code.devrtb.com:7999/rtb/site.git, planRepository.1.branch=RTB-104370, repository.4915203.git.branch=master, planRepository.integrationBranch.username=, planRepository.integrationBranch.name=site, planRepository.1.repositoryUrl=ssh://git@code.devrtb.com:7999/rtb/site.git, repository.4915203.git.username=, planRepository.username=, planRepository.1.revision=c260026d06e5c908d02eae3dd2596643b5c57c10, repository.675414082.name=site, planRepository.integrationBranch.revision=c1efcef27c5fe90f7a4d846bc915fc7665a5f816, planRepository.integrationBranch.repositoryUrl=ssh://git@code.devrtb.com:7999/rtb/site.git, repository.675414082.revision.number=c260026d06e5c908d02eae3dd2596643b5c57c10, repository.675414082.git.branch=RTB-104370, planRepository.integrationBranch.type=bbserver, planRepository.revision=c260026d06e5c908d02eae3dd2596643b5c57c10, planRepository.1.branchName=RTB-104370, repository.revision.number=c260026d06e5c908d02eae3dd2596643b5c57c10, repository.name=site, repository.675414082.branch.name=RTB-104370, planRepository.branch=RTB-104370, repository.4915203.git.repositoryUrl=ssh://git@code.devrtb.com:7999/rtb/site.git, plan.storageTag=plan-675283158, planRepository.1.type=bbserver, planRepository.1.branchDisplayName=RTB-104370, planRepository.integrationBranch.branchName=master, repository.4915203.name=site, planRepository.branchDisplayName=RTB-104370, repository.git.username=, repository.4915203.branch.name=master, planRepository.type=bbserver, planRepository.integrationBranch.branch=master, repository.675414082.git.username=, planRepository.name=site, repository.git.branch=RTB-104370, repository.4915203.revision.number=c1efcef27c5fe90f7a4d846bc915fc7665a5f816, planRepository.1.username=, repository.git.repositoryUrl=ssh://git@code.devrtb.com:7999/rtb/site.git, planRepository.1.name=site, repository.branch.name=RTB-104370, planRepository.branchName=RTB-104370, planRepository.integrationBranch.branchDisplayName=master}
2022-01-19 12:08:08,607 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-15] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent.getPlanKey().getKey().toLowerCase()rtb-site3303
2022-01-19 12:08:08,607 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-15] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent..generic..planRepository.branchNameRTB-104370
2022-01-19 12:08:08,607 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-15] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent..generic..repository.pr.keynull
2022-01-19 12:08:08,607 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-15] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent..generic..planRepository.revisionc260026d06e5c908d02eae3dd2596643b5c57c10
2022-01-19 12:08:08,607 ERROR [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-15] [DiffsAnalyzer] @@DEBUG myChainCompletedEvent..generic..planRepository.repositoryUrlssh://git@code.devrtb.com:7999/rtb/site.git