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

Jason Huntley
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 3, 2012

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
Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 3, 2012

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.

Jason Huntley
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 3, 2012

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 :(

Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 3, 2012

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

Why not have a separate directory with your authentication files?

Jason Huntley
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 3, 2012

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?

Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 3, 2012

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 Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events