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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

54 views 1 0
Join discussion

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