Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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!
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}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register Now
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.