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

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

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 @Paul van Drunen - 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?

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"


Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published yesterday in Confluence

Confluence CVEs and common questions

Two vulnerabilities have been published for Confluence Server and Data Center recently: March 20, 2019 CVE-2019-3395 / CVE-2019-3396 April 17, 2019 CVE-2019-3398 The goal of this article is...

61 views 0 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you