Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

check if build is using plan branch

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 Dec 04, 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

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 Dec 05, 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
Community showcase
Published in Bamboo

Bamboo 101 Video

G’day Community! As we gear up to introduce Bamboo Data Center to the world, we wanted to make sure that we shared a bit more about Bamboo, the product. Our team has put together an overview video ...

223 views 4 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you