Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Bamboo variable for branchname without prefix

Hi we would like to pass the branchname in a buildtask. But currently if it is a feature brach (Bitbucket). It starts with feature/branchname and therefore our builds are not working. Is there a way to not use the prefix or to rewrite the / to a - character.

Hopefully someone can help me.

We are using Gulp tasks to create a package and upload this package to our server.


Thank you in advance.

2 answers

I have solved it already. 


The following code is working for me.


New-Variable -Name "bbranch" -Value ${bamboo.planRepository.branchName}
echo "nieuwe : $bbranch"
If($bbranch -Match 'feature'){
New-Variable -Name "branchprefix" -Value 'feature'
echo "branch prefix = : $branchprefix "
$bbranch -replace 'Luxe/feature/',''
New-Variable -Name "branchname" -Value test
$branchname = $bbranch -replace 'Luxe/feature/',''
echo "branchname = : $branchname"

}ElseIf ($bbranch -Match 'release'){
New-Variable -Name "branchprefix" -Value 'release'
echo "branch prefix = : $branchprefix "
$bbranch -replace 'Luxe/release/',''
New-Variable -Name "branchname" -Value test
$branchname = $bbranch -replace 'Luxe/release/',''
echo "branchname = : $branchname"

}ElseIf ($bbranch -Match 'hotfix'){
New-Variable -Name "branchprefix" -Value 'hotfix'
echo "branch prefix = : $branchprefix "
$bbranch -replace 'Luxe/hotfix/',''
New-Variable -Name "branchname" -Value test
$branchname = $bbranch -replace 'Luxe/hotfix/',''
echo "branchname = : $branchname"

ElseIf ($bbranch -Match 'Luxe_Development'){
New-Variable -Name "branchprefix" -Value 'Development'
echo "branch prefix = : $branchprefix "
$bbranch -replace 'Luxe/',''
New-Variable -Name "branchname" -Value test
$branchname = $bbranch -replace 'Luxe/',''
echo "branchname = : $branchname"


0 votes

Assuming you are using the 'bamboo.planRepository.branchName' Bamboo variable to get the branchname, you can manipulate the variable value in a Script task, write the adjusted value to a file, and then inject it again as a new variable by means of one of the following tasks:

You can then refer to the newly injected variable from subsequent tasks.

HI @Steffen Opel _Utoolity_,


Thank you for your answer. How would you save it to a file via a script task?


thanks in advance.

Hi @paulvandrunendigitaslbi - all Bamboo variables are available as environment variables in the Script task, with details depending on which shell you are using. Unfortunately this is not well documented by Atlassian indeed, please refer to e.g. Utoolity's section on Environment variables for the specific syntax that applies to your scenario.

Once you have access to the original variable in your shell, you can derive a new value with the shell specific tooling for string manipulation and redirect the output to a new file that will be used for the variable injection - for example from PowerShell you could create the Bamboo Variables task format as follows:


# either replace '/' infix with '-' ...
$bamboo_planRepository_branchName.Replace('feature/', 'newBranchName=feature-') >

# ... or drop 'feature/' prefix
$bamboo_planRepository_branchName.Replace('feature/', 'newBranchName=') >


Hi @Steffen Opel _Utoolity_,


I have created the following script but for some reason it does not work.


If(${bamboo.planRepository.branchName} -Match 'feature'){
$branchprefix = 'feature'
echo "branch prefix = : $branchprefix "
$branchname = $bamboo_planRepository_branchName -replace 'Luxe/feature/',''
echo "branchname = : $branchname"
}ElseIf (${bamboo.planRepository.branchName} -Match 'release'){
$branchprefix = 'release'
echo "branch prefix = : $branchprefix "
$branchname = $bamboo_planRepository_branchName -replace 'Luxe/release/',''
echo "branchname = : $branchname"
}ElseIf (${bamboo.planRepository.branchName} -Match 'hotfix'){
$branchprefix = 'hotfix'
echo "branch prefix = : $branchprefix "
$branchname = $bamboo_planRepository_branchName -replace 'Luxe/hotfix/',''
echo "branchname = : $branchname"

 I am getting the following error in the log. 


error 24-Jan-2018 10:08:16 Luxe/release/20180124 : The term 'Luxe/release/20180124' is not recognized as t
error 24-Jan-2018 10:08:16 he name of a cmdlet, function, script file, or operable program. Check the spel
error 24-Jan-2018 10:08:16 ling of the name, or if a path was included, verify that the path is correct an
error 24-Jan-2018 10:08:16 d try again.
error 24-Jan-2018 10:08:16 At D:\Bamboo-home\temp\LPW-TB10-JOB1-2-ScriptBuildTask-3251863757090287516.ps1:
error 24-Jan-2018 10:08:16 4 char:4
error 24-Jan-2018 10:08:16 + If(Luxe/release/20180124 -Match 'feature'){
error 24-Jan-2018 10:08:16 +    ~~~~~~~~~~~~~~~~~~~~~
error 24-Jan-2018 10:08:16     + CategoryInfo          : ObjectNotFound: (Luxe/release/20180124:String) [ 
error 24-Jan-2018 10:08:16    ], CommandNotFoundException
error 24-Jan-2018 10:08:16     + FullyQualifiedErrorId : CommandNotFoundException
error 24-Jan-2018 10:08:16  

Do you have an idea on how i can solve this?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bamboo

Bamboo Data Center on Kubernetes

Hi, If you are running self-managed environments and looking to adopt modern infrastructure, Bamboo Data Center can now be deployed in a Kubernetes cluster. By leveraging Kubernetes, you can easily...

912 views 3 8
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