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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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
4,465,095
Community Members
 
Community Events
176
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.

3 answers

A Bash script to clean the folders in the branch name:

branchNameClean=${bamboo.planRepository.branchName}
echo "Current branch name: ${branchNameClean}"
branchNameClean=${branchNameClean#*/}
echo "Clean branch name: ${branchNameClean}"

If you expect more than one folder you can just repeat the line many times

branchNameClean=${branchNameClean#*/}
branchNameClean=${branchNameClean#*/}
branchNameClean=${branchNameClean#*/}


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:

PowerShell

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

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

 

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
TAGS

Atlassian Community Events