Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to invoke/start a plan programatically with Bamboo 5.11?

I've tried this approach in the link below but it won't compile due to version changes. 

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

1 answer

0 votes
Jeyanthan I Atlassian Team Aug 03, 2017

Hi Anna, I don't know what went wrong with that program. We would need more info on that.

But how about using REST API to trigger a plan?

In my Bamboo 5.15, I was able to trigger a test plan by just running a curl command like below.

curl --user username:password -X POST http://yourbamboohost:8085/rest/api/latest/queue/PROJ-PLA

where PROJ is your project name and PLA is your plan name.

Thank you for the reply. But my requirement is to trigger a bamboo plan upon the completion of an external task which cannot be run via a bamboo task. As you have mentioned I already explored the option to use a rest call to trigger a plan programmatically; however I do not want to maintain certain configurations in the external task , hence the requirement is to trigger a bamboo task via a custom rest service plugin. The sample code provided to trigger a build programmatically does not work in Bamboo version 5.11 and I was not able to configure the relevant code segment.

The code for Bamboo version 5.11 is,

public TestService( BuildExecutionManager buildExecutionManager, PlanExecutionManager planExecutionManager, PlanManager planManager,
VariableDefinitionManager variableDefinitionManager, CredentialsAccessor credentialsAccessor){
this.buildExecutionManager = buildExecutionManager;
this.planManager = planManager;
this.planExecutionManager = planExecutionManager;
this.variableDefinitionManager = variableDefinitionManager;
this.credentialsAccessor = credentialsAccessor;

}
public void setBranchIntegrationService(final BranchIntegrationService branchIntegrationService){
this.branchIntegrationService = branchIntegrationService;
}
public void runPlan(){

BuildContext buildContext = null;
Plan plan = planManager.getPlanByKey("ADT-RRR");
BuildContextBuilderFactoryImpl buildContextBuilderFactory = new BuildContextBuilderFactoryImpl(branchIntegrationService, variableDefinitionManager, credentialsAccessor);
BuildContextBuilder buildContextBuilder = buildContextBuilderFactory.createBuilder();
buildContextBuilder = buildContextBuilder.buildDefinition(plan.getBuildDefinition());
buildContext = buildContextBuilder.build();
buildExecutionManager.execute(buildContext);
}



The following error triggers upon the execution of the above code.

java.lang.NullPointerException
at com.atlassian.bamboo.v2.build.BuildIdentifierImpl.<init>(BuildIdentifierImpl.java:26)
at com.atlassian.bamboo.v2.build.BuildContextImpl.<init>(BuildContextImpl.java:87)
at com.atlassian.bamboo.build.context.BuildContextBuilderImpl.build(BuildContextBuilderImpl.java:133)
at com.testMyService.rest.TestService.runPlan(TestService.java:128)
at com.testMyService.rest.TestService.getMessageFromPath(TestService.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 7.1 is here and is packed with value!

I'm happy to announce that Bamboo 7.1 has been released and it’s overflowing with awesome new features. Top-voted issues First and foremost, a bunch of JAC top voted issues has been delivered - y...

673 views 1 6
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you