How to transform Bamboo variables?

Is there any way to transform Bamboo variables?

We're using Octopus Deploy and we need to supply a version number to the MSBuild process. However, the version number may not be longer than 20 characters. That is a particular problem when using plan branches, since (in order to create unique versions) I need to incorporate some branch identifier, which currently can only be the branch name, which in turn contains the whole JIRA issue description (since we're using the whole JIRA, Stash and Bamboo pipeline). So I need to do some serious trimming, e.g. through regex replacements, getting substrings, etc. 

All suggestions are welcome!

2 answers

1 accepted

2 votes
Accepted answer

You have 2 options but you need Bamboo 5.7 or later. Both exploit the fact that in Bamboo 5.7 it is possible to create variables during build run time and use them later in deployment version name.

Option 1:

Create a script (.bat or powershell) that will do all the things you need. Exploit the fact that all the Bamboo variables are exported as system variables when running Script task. Write the result into a .properties file. Use Inject Variables task to read the properties from the file into Bamboo variables. Make sure to use Result scope. Use the injected variable in version naming pattern for the deployment project.

Option 2:

Instead of using script task + inject variable you can implement custom task plugin that will do the same.

Marcin, thanks for the very quick and to-the-point answer. I went for option 1 and it works! I did have quite a bit of trouble getting it to work across Windows (our build server) and Linux (our Bamboo server): Powershell messes up character encoding. Here's the issue number extraction I went for: 

$Env:bamboo_planRepository_branchName -match "^(|.+\/)([A-Z]+\-\d+).*" > $null
If ($matches.count -gt 2) {
    $name_value = "jiraIssueNumber=$($matches[2])"    
} Else {
    $name_value = "jiraIssueNumber=none"
    Write-Host "Match count=$($matches.count)"
# THE FIRST write-output IS MANDATORY!
write-output "foo=bar" | out-file bamboo_extra_variables.txt -encoding utf8
write-output $name_value | out-file bamboo_extra_variables.txt -encoding utf8 -append

In addition, I had to pass in the bamboo.planBranch.branchName through the environment variables:


Suggest an answer

Log in or Sign up to answer
Community showcase
Asked Thursday in Jira Ops

I'm John Allspaw, Ask Me Anything about incident analysis and postmortems

I'm John Allspaw, co-founder of   Adaptive Capacity Labs, where we help teams use their incidents to learn and improve. We bring research-driven methods and approaches to drive effective inciden...

4,341 views 20 13
View question

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