How do I store settings per plan in a repository plugin?

I can't seem to find a way to get the plan key from prepareConfigObject:

public void prepareConfigObject(@NotNull BuildConfiguration buildConfiguration) {

}

I need to store specific configuration items for a repository plugin I'm creating per plan. It's unlikely the same repo settings will be used for every plan.

What I actually need to store is a configuration file per plan. This has to be done as a file and can't be done using the configuration.setProperty mechanisms. I've tried getting the base working directory, but that only takes me to the build-dir directory:

File parentDirectoryFile=this.buildDirectoryManager.getBaseBuildWorkingDirectory();
String parentDirectory=parentDirectoryFile.getAbsolutePath();
String workingDirectory=parentDirectory+File.separator+this.getShortKey();
 File f = new File(workingDirectory+"/config.txt");

I need access to the plan directories under build-dir so I can store settings per plan. I don't know, maybe I'm going about this the wrong way. Any input is greatly appreciated.

1 answer

1 vote

Settings per plan: buildConfiguration object is already per-plan, i.e. whatever you store in it or retrieve from it will be for specific plan.

Accessing build directory: If you have access to BuildContext, you should access the build directory with com.atlassian.bamboo.v2.build.BuildContextHelper#getBuildWorkingDirectory .

If you don't have access to it, I'd need to know more about your use case.

I'm working a thrid party authenticator, which requires a file handle as a parameter, and the AbstractStandaloneRepository class. WHen you store your settings in the repository settings tab under your plan, prepareConfigObject get's called, then validate. BuildContext is not accessible from within this method. I need to create this file handle somehow so it's saved per plan. RIght now, I can store in a separate directory under build-dir, but when I setup a new plan, this will get overwritten. I need to have this file saved per plan. I wish the authenticator didn't work this way, and only took the ssh private key as string, but it has to have a file :(

Working directory is not your only problem - change detection will need to authenticate too.

Why not have a separate directory with your authentication files?

Currently, I'm trying to create a separate directory for this purpose, or at least one nested in the build plan directory. There's no guaruntee they will use the same key for every plan as projects vary. Do you have an example in mind?

The problem is that during change detection you will not have a build directory because the build has not yet started (and potentially won't start). You need to have a yet different directory.

Suggest an answer

Log in or Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,096 views 0 5
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot