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

check if build is using plan branch

redline18 December 3, 2019

Hey there, I am looking for a way to check if the running build is executed on branch or plan level.  Preferably in powershell script.  Task at hand is to use a plan branch name if build is using a plan branch otherwise it should use the planKey as a folder in output directory.    Since the bamboo.shortPlanName always exists even when the build is using the plan, just checking if the variable is null or empty is not enough.

1 answer

0 votes
Jimmy Seddon
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 4, 2019

Hi @redline18,

You are correct that the bamboo.shortPlanName always exists, but we also know that when it's running as the "main" build instead of a branch, the name is the same name as the build plan where as when it's running as a branch it is the name of the branch. 

So as long as you don't create or use branch names with the same name as your build plan you should be able to do a string comparison to ensure that the bamboo.shortPlanName isn't the same as your plan name.

I hope that helps!

-Jimmy

redline18 December 4, 2019

Thanks for the explanation Jimmy, I do think that there should be some kind of boolean variable for that.  Sometimes giving a plan branch same display name as the plan itself is unavoidable if someone outside of devops decides to do that.  It doesn't solve the issue completely because it still vulnerable to the scenario I mentioned earlier.  There is gotta be a better way to determine.  I am surprised bamboo doesn't have a variable for that.  Another solution is to enforce a unique name.

 

I have found this bit of ps code that supposed to flag if bamboo build is using plan branch or not but I cannot seem to find much information about how this code actually works.

 

param(
[Parameter(Mandatory=$true)][string]$DeleteType,
[string]$BambooType = "planbranch",
[string]$BuildType,
[string]$RetentionDays = "-7",
[switch]$RetainByDays
)

Jimmy Seddon
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 5, 2019

Yeah I'm not sure how that is determining if it's a plan branch or not I'm not aware of anything that exposes that to the end user.  However, doing a quick search, this might help you our as well:

https://community.atlassian.com/t5/Bamboo-questions/How-to-determine-what-branch-of-plan-is-running/qaq-p/882589

If you look at the provided answer, you could instead check against the name of the linked repository branch.  You know for a fact what the branch name is that is set as the main branch for the linked repository which will be the master branch for that plan, nothing can change that, if that name doesn't match the 
bamboo.planRepository.<position>.branchName

Then you know you are running on a plan branch.

-Jimmy

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events