Are bamboo variables automatically available as environment variables?
Asked Answered
E

5

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"
Exemption answered 13/4, 2013 at 12:16 Comment(0)
E
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.

Exemption answered 14/4, 2013 at 0:15 Comment(1)
Still waiting for the bamboo release where it's finally a viable alternative to Jenkins.Stupefaction
C
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.

Crookback answered 21/11, 2013 at 22:37 Comment(1)
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.Woodbury
E
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.

Exemption answered 14/4, 2013 at 0:15 Comment(1)
Still waiting for the bamboo release where it's finally a viable alternative to Jenkins.Stupefaction
E
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'
Endocardium answered 2/6, 2017 at 14:2 Comment(0)
K
1

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
Kindly answered 6/12, 2021 at 10:56 Comment(1)
Both bamboo.buildNumber and bamboo_buildNumber work on linux.Woodbury
S
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
Soriano answered 16/3, 2023 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.