Invoke a bamboo job programatically

Hi, 

I have a requirement to invoke a bamboo job from a bamboo plugin. Th erequirement is to rerun specific jobs upon failure.  Using rest calls does not seem to be an option for various reasons.  I've found two options so far, to capture the failed job event. 

1. Event Listener - JobCompletedEvent

2. PostJobAction Module

 

And I use the following code to invoke the plugin, however this snippet throws null exceptions and I'm not sure if it only invokes the failed job or the whole build. Is there an alternative way to do this?

 @ComponentImport
private VariableDefinitionManager variableDefinitionManager;
@ComponentImport
private ImmutablePlanCacheService immutablePlanCacheService;
@ComponentImport
private CredentialsAccessor credentialsAccessor;
@ComponentImport
private BuildResultsSummaryManager buildResultSummaryManager;
@ComponentImport
private BuildDefinitionManager buildDefinitionManager;
@ComponentImport
private ChangeDetectionManager changeDetectionManager;


public PostTaskListener(VariableDefinitionManager variableDefinitionManager, ImmutablePlanCacheService immutablePlanCacheService, CredentialsAccessor credentialsAccessor, BuildResultsSummaryManager buildResultSummaryManager, BuildDefinitionManager buildDefinitionManager, ChangeDetectionManager changeDetectionManager) {
this.variableDefinitionManager = variableDefinitionManager;
this.immutablePlanCacheService = immutablePlanCacheService;
this.credentialsAccessor = credentialsAccessor;
this.buildResultSummaryManager = buildResultSummaryManager;
this.buildDefinitionManager = buildDefinitionManager;
this.changeDetectionManager = changeDetectionManager;
this.jobExecutionManager = jobExecutionManager;
}

public void handleEvent(Event event) {

if(event instanceof JobCompletedEvent){

JobCompletedEvent jobCompletedEvent = (JobCompletedEvent) event;

ResultsSummary resultsSummary = buildResultSummaryManager.getResultsSummary(jobCompletedEvent.getPlanResultKey());

BuildDefinition buildDefinition = buildDefinitionManager.getBuildDefinition(((JobCompletedEvent) event).getPlanKey());

this.buildContextBuilderFactory = new BuildContextBuilderFactoryImpl(new BranchIntegrationServiceImpl(immutablePlanCacheService), variableDefinitionManager, credentialsAccessor);
BuildContextBuilder buildContextBuilder = buildContextBuilderFactory.createBuilder();
BuildContext buildContext = buildContextBuilder.build();

jobExecutionManager.requestExecution(buildContext);

}
}

 

Link : https://developer.atlassian.com/bamboodev/development-resources/bamboo-developer-faq/how-do-i-start-a-build-programatically   

0 answers

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,568 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you