How do I get Bamboo to use different variables in an auto branch build?

I can see there's a way to configure variables against specific branch plans, once they have been created, but is there a way to set some defaults that only apply to branch plans that are automatically created (when the code branch is pushed into Stash?)

One case is where I need SonarQube to run in incremental/preview analysis in all branches, and only run in full "analysis" mode when the main plan builds.

1 answer

1 vote

Bamboo doesn't have that feature (yet), but I think you can still achieve what you need. Here's how:

The name of the current branch is available in variable called bamboo.planRepository.branchName. You can match this against 'master' (or whatever your main branch is called).

Now, if you run SonarQube from script task then the rest is easy. Things get a bit complicated if you absolutely need some Bamboo variables to be set. In that case:

  • create a script that would write the values you need to a .properties file, checking branchName to see which values should be written
  • use Inject Variables Task to read those variables
  • use injected variables as any other variable in subsequent tasks

In case you have multiple Jobs in your build, you might want to create a 'preparation stage' that would produce all the variables. If you set 'result' scope in the Inject Variables Task, the variables become available in all subsequent stages of the plan. (and not just the current Job)

Note that the above applies to Bamboo 5.7 and later.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
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,813 views 0 6
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