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

This widget could not be displayed.

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.

This widget could not be displayed.

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 Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

169 views 1 3
Join discussion

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