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.
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!
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.
[string]$BambooType = "planbranch",
[string]$RetentionDays = "-7",
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:
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
Then you know you are running on a plan branch.
G’day Bamboo customers, Bamboo DC 8.1 is now available with it the following features and programs: SAML 2.0, OpenID Connect, and Crowd SSO In order to help admins with a simplified user manage...
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