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
Community showcase
Posted Monday in Confluence

Organizing your space just got easier - Page Tree Drag & Drop is here

Hi Community! I’m Elaine, Confluence Product Manager. You may have read my earlier post about page tree in space navigation sidebar. I'm excited to share another improvement that helps you organize ...

101 views 3 4
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