How to transform Bamboo variables?

Pascal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2015

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
Answer accepted
Marcin Gardias
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 7, 2015

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.

1 vote
Pascal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 8, 2015

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
TAGS
AUG Leaders

Atlassian Community Events