11

I am trying to access Bamboo's variables as environment variables in my build script (PowerShell).

For example, this works fine in TeamCity

$buildNumber = "$env:BUILD_NUMBER"

And I expected this to work in Bamboo

$buildNumber = "$env:bamboo_buildNumber"
Thomas Langston
  • 3,743
  • 1
  • 25
  • 41
Adam B
  • 506
  • 1
  • 5
  • 13

5 Answers5

9

In the current version of Bamboo (5.x), the following environment variables work for me in Bash on an Amazon EC2 Linux client within a Bash script. It should be very similar in PowerShell.

  • ${bamboo.buildKey} -- The job key for the current job, in the form PROJECT-PLAN-JOB, e.g. BAM-MAIN-JOBX
  • ${bamboo.buildResultsUrl} -- The URL of the result in Bamboo once the job has finished executing.
  • ${bamboo.buildNumber} -- The Bamboo build number, e.g. 123
  • ${bamboo.buildPlanName} -- The Bamboo plan name e.g. Some Project name - Some plan name

You can see the full list of Bamboo build variables on the Atlassian Bamboo build variable documentation page.

Steve HHH
  • 12,947
  • 6
  • 68
  • 71
  • This is not OP asked: it's about the env vars field on a script task and not about accessing bamboo vars from within a script task. – Alex Jul 07 '21 at 16:07
6

Typical. It's a bug.

https://jira.atlassian.com/browse/BAM-11824?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

https://answers.atlassian.com/questions/66109/accessing-build-specific-variables-from-script-without-having-to-use-environment-variables-box-on-script-config-page

So I have to resort (meanwhile) to add the environment variable in the script task.

Adam B
  • 506
  • 1
  • 5
  • 13
2

Yes, Bamboo variables appear to be available automatically as environment variables in Bamboo 5.9.4. The following worked for me as an inline Powershell:

$revision = $Env:bamboo_planRepository_revision
$buildNumber = $Env:bamboo_buildNumber
$text = "$revision - $buildNumber"
$text > 'Version.txt'
Thomas Langston
  • 3,743
  • 1
  • 25
  • 41
1

Short answer to this question is :- No it doesn't work in bamboo.

You try to use bamboo global variable as environment variable inside of a bamboo build environment.

  • Get an idea about how to address a global variable in bamboo.link

Define your variable name as key and add this global variable name as value. (add variable in plan configuration), then during the plan you can access that global variable inside whatever script(power shell /shell /bash) you have created.

Don't forget to add the variable name that you defined , inside of the script configuration as environment variable.

enter image description here

  • Use this link to define the global variable as plan variable. link
Pasindu Perera
  • 489
  • 3
  • 8
0

Just keep in a mind, there are some difference in a var naming convention at platforms:

  • at unix it should be bamboo.buildNumber
  • at win . sign should be replaced by _ - bamboo.buildNumber >> bamboo_buildNumber