How to create multiple plans for multiple projects
Asked by Hema:

Hi,

I am new with Bamboo. I am trying to create multiple plans for multiple projects using java spec and want to pass dynamic values to java spec like application name, repo link, bamboo server url. Can anybody help me on this how to achieve this and project structure in bitbucket.


Answers:
author: Jimmy Seddon
body: Hi [@Hema](/t5/user/viewprofilepage/user-id/3179637),

First, I do not claim to be any sort of expert in how to properly structure a java project, so I can share what I did but I'm sure there are better ways out there.

Becuase I setup a java project for our specs that uses Bamboo to build and deploy the specs project, I chose not to use a properties file but instead to pass in command line arguments that are using bamboo variables.

From there I have a class that runs the main method and all it is responsible for doing is generating all of the build plan objects and then running the publish command to create new or update existing if that same plan has already been deployed to the server.

Next from there I have a Build plan class (technically two as we are changing the structure in our projects from one standard set to another)

This class has a few fields that get populated when it is called in the main method by the constructor and it has a number of methods (one for each type of task that will exist in the plan). I then create all the tasks calling the methods that create the various types of tasks and passing in the relevant information the task needs (This is where I used the "View Plan as Java Specs" action when editing an existing plan to have a template of what it is expecting so I knew the structure I needed to build.

From there it was a matter of making the task methods generic enough that I don't need a method for every unique task and a bunch of hard coded values, but specific enough that I can do what i need without a ton of if/else logic in the task method.

I hope that helps give you a bit more detail into what I've done.

-James

comments: author: Hema
body: Thanks [@Jimmy Seddon](/t5/user/viewprofilepage/user-id/512822)


author: Hema
body: Hi [@Jimmy Seddon](/t5/user/viewprofilepage/user-id/512822)   
Now I am facing another issue on prod bamboo instance. Creating Plan repository using bitbucket server from bamboo spec is not creating. It is giving error like Request to stash failed. Returned with 401. Response body is empty. When i saw log for it it is failing at OAuthApplinkexecutor. I am not getting why it is failing with 401. When I am passing ssh keys and app link for creating plan repo.  
When I published plan from local to bamboo server then creating plan repository using bitbucket server but not with bamboo spec.  
When I tried to create plan repository using GitRepository from bamboo spec then it is working but using bitbucket server repo, it is failing.  
Please help me.


author: Jimmy Seddon
body: Hi [@Hema](/t5/user/viewprofilepage/user-id/3179637),

I'll be honest I haven't actually created linked repositories with Bamboo Specs, I have always just reused existing linked repositories.

However, a 401 error would indicate that your credentials are invalid. Given where it's failing I'm wondering if you might have a error in the way/value you provided for the SSH private \& public keys.

I hope that helps.

-James


author: Hema
body: Hi ,  
Thanks for answering.  
I am also trying to create template and pass values to it.  
And I am trying to read some values from properties file and pass to method.  
So what should be structure of project when we use prop file


author: Jimmy Seddon
body: Hi [@Hema](/t5/user/viewprofilepage/user-id/3179637),

Welcome to the community!

What I did to accomplish this was first I exported the Java specs template, then I used that a a blue print to create a new class specific to the type of dot net project we are building.

We made sure that our developers are building the nuget package projects in a consistent manner so that we could make a generic build plan class that would take in a few pieces of unique information such as name, plan key, linked repo name and a couple of boolean values for options tasks to be enabled or disabled.

The main class itself would then have a number of methods that would build the structure of the plan based on the template I stated with while using the values that were past in via the main method.

Lastly, I set this up as a build plan \& deployment project itself so that all I have to do now is update the main method and check in the changes and it will within seconds create a new build plan with the values specified.

I may have over engineered this a bit but it's saving me hours of work at a time.

I hope that helps answer your question.

-James


Tags: bitbucket