Documentation for Bamboo 4.0.x. Documentation for earlier versions of Bamboo is available too.

Variables can be used to set static values that are used when building plans in Bamboo.

  • Global variables are defined across your entire Bamboo instance, and have the same (static) value for every plan that is built by Bamboo. .
  • Plan variables are similar to global variables, but are defined for specific plans. Plan variables override global variables with the same name. You can also override a plan variable for a build, if you have triggered the build manually.
  • Build-specific variables are evaluated by Bamboo dynamically at build time. The source of a build-specific variable can either be a Bamboo property or one of the default plugins (assuming they have been enabled).
  • System variables also apply across your entire Bamboo instance and inherit their values from system or environment variables of the same name.

Specifying variables

Global variables

See Defining global variables for information on defining global variables.

The usage format for all global variables is:

${bamboo.globalVarName}

Plan variables

See Defining plan variables for information on defining plan variables. You can override a plan variable for a build, if you have triggered the build manually. For details, see Triggering a plan Build Manually.

The usage format for all plan variables is:

${bamboo.varName}

Build-specific variables

The following build-specific variables are also available by default:

Build-specific variable

Source

Description

buildKey

Bamboo property

The plan key for the current job, e.g. BAM-MAIN-JOBX

buildNumber

Bamboo property

The Bamboo build number, e.g. 123

buildPlanName

Bamboo property

The Bamboo plan name e.g. Some Project name - Some plan name

buildTimeStamp

Bamboo property

The time when build was started in ISO 8601 format e.g. 2010-01-01T01:00:00.000+01:00

buildForceCleanCheckout

Bamboo property

Whether the "Force Clean Build" option was used, values:true/false

build.working.directory

Bamboo property

The working directory that the build is being executed on

manualBuildTriggerReason.usernameBamboo propertyThe user who triggered the manual build

repository.revision.number

Plugin

The revision number

repository.previous.revision.number

Plugin

The previous revision number (might not exist if for example is initial build)

custom.svn.revision.number

Plugin

(For Subversion only) The revision number

custom.svn.lastchange.revision.number

Plugin

(For Subversion only) The last changed revision number

custom.svn.username

Plugin

(For Subversion only) User name used for repository authentication

repository.svn.repositoryUrl

 

(For Subversion only) The repository url

custom.cvs.last.update.time

Plugin

(For CVS only) The last updated timestamp

custom.cvs.last.update.time.label

Plugin

(For CVS only) The last updated timestamp to be used as a label for post build result labelling. The spaces in the cvs version string are replaced with '_'

custom.p4.revision.number

Plugin

(For Perforce only) The change set number

custom.p4.username

Plugin

(For Perforce only) User name used for repository authentication

custom.p4.port

Plugin

(For Perforce only) Port used for repository communication

custom.p4.client

Plugin

(For Perforce only) Client used for repository communication

repository.hg.repositoryUrl

 

(For Mercurial only) The repository url

repository.hg.branch

 

(For Mercurial only) The branch

repository.hg.username

 

(For Mercurial only) User name used for repository authentication

  • System variables also apply across your entire Bamboo instance and inherit their values from system or environment variables of the same name.

The usage format for all build-specific variables is:

${bamboo.varName}

System variables

The usage format for all system variables is:

${system.<variable>}

For example, if you have a system variable MYPATH=C:\MyPath; you can use a Bamboo system variable system.MYPATH which will inherit the same value as the system variable.

Using variables

Variables can be used in the following fields of your build plan:

Field

Global

Build-specificSystem

Goal (for Maven builders only)
— see Configuring tasks

(tick)

(tick)(tick)

Build File (for Ant and NAnt builders only)
— see Configuring tasks

(tick)

(tick)(tick)

Target (for Ant and NAnt builders only)
— see Configuring tasks

(tick)

(tick)(tick)

Options (for NAnt builders only)
— see Configuring tasks

(tick)

(tick)(tick)

Script (for Scripts only)
— see Configuring tasks

(tick)

(tick)(tick)

Argument (for Scripts and Custom Commands only)
— see Configuring tasks

(tick)

(tick)(tick)

Environment Variables
— see Configuring tasks

(tick)

(tick)(tick)

Repository URL (for Subversion repositories only)
— see Specifying the source repository

(tick)

(error)(tick)

Web Repository URL (for Subversion, CVS and Perforce repositories)
— see Specifying the source repository

(tick)(error)(tick)

CVS Root (for CVS repositories only)
— see Specifying the source repository

(tick)

(error)(tick)

Branch name (for CVS repositories only)
— see Specifying the source repository

(tick)

(error)(tick)

 

Examples of variables usage

Maven example

For example, you may want your Maven 2 version to be determined by Bamboo. In Maven 2 pom.xml you may have:

...
<groupId>com.atlassian.boo</groupId>
<artifactId>boo-test</artifactId>
<packaging>jar</packaging>
<version>1.1.${env.bambooBuildNumber}-SNAPSHOT</version>
...

You can then specify the following in the Goal field of your build plan:

clean package -DbambooBuildNumber=${bamboo.buildNumber}

When the command runs, Bamboo will replace the buildNumber with the actual number (e.g. 1102), which will be passed to the underlying Maven build to use. The command will then produce a jar that looks like this: boo-test-1.1.1102-SNAPSHOT.jar.

Ant example

You can then specify the following in the Target field of your build plan:

-f build.xml -DbambooBuildNumber=${bamboo.buildNumber}

When the command runs, Bamboo will replace the buildNumber with the actual number (e.g. 1102), which will be passed to the underlying Ant build to use.

Specifying capabilities as variables

You can also specify a capability to be used in a similar way to a global variable.

The format of the capability should be as follows:

${bamboo.capability.<capability_key>}

For example,

  • Custom

    ${bamboo.capability.<capability_key>}
  • JDK

    ${bamboo.capability.system.jdk.<jdk_label>}
  • Builder

    ${bamboo.capability.system.builder.<builder_type>.<builder_label>}
    e.g. ${bamboo.capability.system.build.maven.Maven1}
  • Perforce

    ${bamboo.capability.system.p4Executable}

If you click on a capability, the specific capability key will be contained in the URL.

Please note, the space characters in the URL will be replaced with '+' characters. We recommend that you do not use capability labels with space characters, if you wish to use them as variables. A possible solution for space characters is to format them with '${}' symbols, however, this does not work in all cases.

Using capabilities

Global and Build-Specific Variables can be used in a specific fields of your build plan, as specified above. For capabilities,

  • System Capabilities are available to all of these fields, (i.e. global and build-specific).
  • Agent Capabilities (i.e. agent-specific and shared/server capabilities) are available only to the build-specific fields. (i.e. not available to Repository URL, CVS Root or Branch name.)

For example,

If you wanted to specify a system variable, but have it set to different values on each agent, do the following:

  1. Set the following as a system environment variable field on the Builder tab:

    ${bamboo.capability.thatsystemvariable}
  2. Specify the system environment variable as a custom capability on each of your agents, and set to the capability to the different values, as desired.

24 Comments

  1. Anonymous

    Which variable should I use in order to find the current build directory?

    1. Anonymous

      build directory - ${bamboo.projectBaseDir}

      I beleive this is from Bamboo, not a plugin.

      1. Anonymous

        ${bamboo.projectBaseDir} doesn't seem to work on 2.6. I really need access to this variable though. Any other suggestions?

        1. AjayA

          Folks,

          The {bamboo.projectBaseDir} variable is actually provided by the Bamboo pre/post build plugin:

          https://studio.plugins.atlassian.com/wiki/display/BPBC/Home

          Can you try installing this plugin?

          Cheers,
          Ajay.

          1. Robert Crosbie

            For those who don't want to use the pre/post plugin, you can construct the build directory yourself.

            Create a custom capability on your agent(s) called build-dir.  For example:

            build-dir = C:\bamboo\xml-data\build-dir

            In your build plans you can use build-dir and buildKey to construct the project build directory:  For example:

            BUILDROOT=${bamboo.capability.build-dir}\${bamboo.buildKey}
            

            I still think Bamboo should provide a build directory variable by default though.

            1. Jared Morrow

              Thanks for your comment, you are a life saver.   I tried using the variable buildWorkingDir that was listed elsewhere in the documentation with no luck, so I'm sure glad I got pointed to this page to see your comment.   I agree, I think there should be a default variable for working directory because I can see that being one of the most often used ones.

  2. Anonymous

    Is there an explicit list somewhere of the Bamboo variables?

  3. Ulrich Kuhnhardt

    The available variables are listed above. If you need other variables that represent bamboo parameters you can make them available via a plugin and persist them as custom.<my-variable>.

  4. Anonymous

    Could I possibly get an nant example?  And is there anything special to be done in order to pass values back to Bamboo? 

  5. xavier lannoye

    Hi

    I cannot access bamboo.custom.svn.revision.number varaible in my ant scripts.

    any suggestion welcome

    regards

    1. Alan Farkas

      Are you passing the variable into your Ant script via the Bamboo Builder Panel?

      ex: svn.rev.num="${bamboo.custom.svn.revision.number}"

      In your ant script, you would reference this variable as such:

      "${env.svn.rev.num}"

  6. xavier lannoye

    Hi

    I finally got it work using this way:

    in the builder tab, add the following parameter to the ant script (in "target" field)

    -Dmy.svn.revision=${bamboo.custom.svn.revision.number}
    
    

    then in my ant script I can reference those variable using

    $env.my.svn.revision
    
    

    et voilà

    regards

  7. user-4cc9e

    Hi,

    Is-it possible to know the current user (how is executing the build) via the build-specific variables?

    I try to use the builder 'ant' to send an email on behalf of this user...

    Thanks,

    Bruno

  8. user-4cc9e

    I did the following test: Send an email with substitution

    1. I have a plan with ant as builder.

    2. System Env Variables: -Dmy.bamboo.buildKey=${bamboo.buildKey} -Dmy.bamboo.buildNumber=${bamboo.buildNumber} -Dmy.bamboo.buildPlanName=${bamboo.buildPlanName} -Dmy.bamboo.buildTimeStamp=${bamboo.buildTimeStamp}

    3. build.xml

    <project name="My Build" default="war" basedir=".">
        <target name="init">
            <property file="build.properties" />
            <property environment="env" />
        </target>
        
        <target name="request" depends="init" description="Send an email with bamboo vars">
    	    <mail from="me@company.com" tolist="me@company.com" messagefile="Test.txt" subject="Test var bamboo"/> 
        </target>
    </project>
    

    4. Test.txt

    Testing bamboo variables
    bamboo.buildKey = ${env.my.bamboo.buildKey}
    bamboo.buildNumber = ${env.my.bamboo.buildNumber}
    bamboo.buildPlanName = ${env.my.bamboo.buildPlanName}
    bamboo.buildTimeStamp = ${env.my.bamboo.buildTimeStamp}
    

    5. Result

    Testing bamboo variables
    bamboo.buildKey = SDBX-SDBX
    bamboo.buildNumber = 12
    bamboo.buildPlanName = ${bamboo.buildPlanName}
    bamboo.buildTimeStamp = ${bamboo.buildTimeStamp}
    

    7. Remarks

    Only buildKey and buildNumber are replaced by their value.

    Is-it a bug or one undocumented feature?

    We use bamboo version 2.4.2 build 1602

    1. user-4cc9e

      (sad) bamboo.buildPlanName and bamboo.buildTimeStamp were not substitued in the version 2.4.2 (sad)

  9. Anonymous

    In the bamboo  I am entering 

    cmcc_opts="D:/myworkspace" in the system variables. I am trying to fetch the variable from ant as ${system.cmcc_opts}

    But this is not returning me the correct result. Please suggest me some solution

  10. Anonymous

    It would be nice if the table had a column about which Bamboo versions support the variable. It seems my current version does not have "custom.svn.lastchange.revision.number"...

  11. Anonymous

    The buildKey now gives the composite plan-job name, not the plan name.

    e.g. "<myplan>-JOB1" by default

    It would be good if we could still get the actual plan name.

  12. Jared Morrow

    If documentation isn't kept up-to-date and isn't correct for many versions of the tool, what is the point of the documentation?

    Is there a way to get JUST the plan name?   

    buildPlanName returns "Some Project name - Some plan name" and I need ONLY the plan name.

  13. Anonymous

    Hi, What is the bamboo property represent current user logged in? I want to pass the property to ant script to let the ant script know who is running the script. thanks very much

    1. Chris Ferry

      Can someone at Atlassian answer this?  I, as well, need to pass the "current user" value to an external script to notify users who has executed the build plan.

      1. PiotrA

        Check this out: https://jira.atlassian.com/browse/BAM-7334 

        I reckon the feature you ask for will be (or is already?) implemented in the incoming Bamboo 3.3. I don't think it was possible in the older Bamboo versions to pass the "current user" value to the external scripts without some kind of external plugin...

  14. Jan Swaelens

    I am looking to implement a link to the bamboo build page inside our application, to allow users to easily see what issues are fixed in the build and which features are added ...

    Is there a way to get to the actual bamboo root URL? With that I can manage to add the other path parts up to the relevant plan & build number.
    The only thing I can think of is define the root URL as a global variable, but wouldn't it be nice to have this built in?

    thanks 

  15. Aaron Evans

    How can you access Bamboo plan or global variables from a shell script task?