Missed Team ’24? Catch up on announcements here.

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

Programatically create Plan

Dhepu Nettady UST February 1, 2016

I am trying to develop an application which will create n number of plans. The REST API provided by bamboo does not have API's to create plans. So I am thinking of creating a Bamboo REST Plugin myself and develop API's to create Plan.

I am using Latest version of Atlassian SDK. I am able to create sample REST API's. But I am not able to create Plan using REST API. I am using PlanManager class to create Plan. But the planManager.createPlan(plan) method throws error

java.lang.IllegalArgumentException: Don't know how to handle permissions for com.....external.impl.MyPluginComponentImpl$1@921f7314

I am extending the class com.atlassian.bamboo.plan.AbstractPlan to create a concrete class for Plan interface.

Please help me.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 2, 2016

Hello @Dhepu Nettady UST,

Try to create plan with provided code

final BuildConfiguration buildConfiguration = new BuildConfiguration();
final Map<String, Object> context = new HashMap<>();
context.put(PlanCreationService.EXISTING_PROJECT_KEY, "PROJ");
context.put(ChainCreationService.CHAIN_KEY, "TEST");
String key = chainCreationService.createPlan(buildConfiguration, new ActionParametersMapImpl(context), PlanCreationService.EnablePlan.ENABLED);
PlanKey planKey = PlanKeys.getPlanKey(key);
//it's required to refresh caches and notify listeners
chainCreationService.triggerCreationCompleteEvents(planKey);

And then add stages and jobs with com.atlassian.bamboo.plan.stage.StageService.addStage() and com.atlassian.bamboo.plan.job.JobService.addJob()

Dhepu Nettady UST February 2, 2016

I pasted your code in to my createPlan REST API implementation.

When I invoked the REST API I am getting PlanCreationException

[INFO] [talledLocalContainer] com.atlassian.bamboo.build.PlanCreationException: Failed to create new plan.  No user was found in the context

[INFO] [talledLocalContainer]     at com.atlassian.bamboo.build.creation.PlanCreationTemplate.validateThrowingPlanCreationException(PlanCreationTemplate.java:570)

[INFO] [talledLocalContainer]     at com.atlassian.bamboo.build.creation.ChainCreationServiceImpl.getDefaultPermissionsForPlan(ChainCreationServiceImpl.java:245)

[INFO] [talledLocalContainer]     at com.atlassian.bamboo.build.creation.PlanCreationTemplate.createPlan(PlanCreationTemplate.java:244)

[INFO] [talledLocalContainer]     at com.atlassian.bamboo.build.creation.ChainCreationServiceImpl.createPlanAndKey(ChainCreationServiceImpl.java:574)

[INFO] [talledLocalContainer]     at com.atlassian.bamboo.build.creation.ChainCreationServiceImpl.createPlan(ChainCreationServiceImpl.java:543)

How can I add a user to the context?

Dhepu Nettady UST February 2, 2016

Thanks,

I am able to create Plan.

In had to add Basic Authentication to the REST request.

And also I had to add the below code also. Other wise IllegalArgumentException is coming.

buildConfiguration.addProperty(Repository.SELECTED_REPOSITORY, NullRepository.KEY);
Dhepu Nettady UST February 2, 2016

I have a question here.The Repository.SELECTED_REPOSITORY is deprecated as per javadoc. "Deprecated. since 3.3 repository definition is no longer part of BuildConfiguration"

Is there any other way other than this deprecated constant?

Shivaprasad September 15, 2016

How do you get access to chainCreationService here ?

TAGS
AUG Leaders

Atlassian Community Events