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
Published 9 hours ago in Jira Ops

Jira Ops Early Access Program Update #2: Let’s talk severity levels

Welcome to your weekly Jira Ops Early access program update, where we’re sharing news and updates on Jira Ops' progress as we work toward our 1.0 release. If you ever want to drop us feedback or idea...

20 views 0 0
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