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

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!
# THE FILE STARTS OF WITH INVALID CHARACTERS, WHICH
# SCREWS UP THE FIRST NAME VALUE PAIR; HENCE THE DUMMY PAIR
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:

bamboo_planRepository_branchName=${bamboo.planRepository.branchName}

Suggest an answer

Log in or Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,087 views 0 5
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot