Bamboo variables

Variables can be used to make values available when building plans in Bamboo.

  • 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 it is enabled).
  • Deployment variables are available when deploying a project. 
  • System variables also apply across your entire Bamboo instance and inherit their values from system or environment variables of the same name.
  • Global variables are defined across your entire Bamboo instance and have the same (static) value for every plan that is built by Bamboo. See Defining global variables.
  • 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 trigger the build manually. See Defining plan variables.

Use variables

Variables can be used in all fields of a task or deployment, with the exception of password fields. Use the following format when referencing a variable:

${bamboo.variableName}

You can override a plan variable for a build if you trigger the build manually. See Triggering a plan build manually.

You can reference a variable from another variable. For example, consider having the following variables:

  • var1 = Hello
  • var2 = world

You can create another variable that references the two other ones.
GREET

${bamboo.var1} ${bamboo.var2}! 

Bamboo will resolve the variable as Hello World!

You can:

  • Reference a global or context-specific variable in a build plan or deployment project
  • Reference a variable that references another one. Deep recursion is allowed.

There are a couple of limitations:

  • Referencing a variable that is not defined is an error. The whole build or the deployment will fail if you reference such a variable.
  • Cycles are not allowed and are considered a build or deployment project error.

Define custom variables

You can define your own custom variables using a format similar to the one above. However, you cannot create a variable name that is already in use by Bamboo.

For information on how to define your own variables in Bamboo, see the following Atlassian articles:

Build-specific variables

The following build-specific variables are available by default:

  • System variables apply across your entire Bamboo instance and inherit their values from the system or environment variables of the same name.
  • In the variable names from the table, <position> is an optional parameter that specifies the position of the repository in the plan's repository list. If omitted, the first repository in the list is used.
  • Third-party repository plugins can expose their own variables.

Build-specific variable

Description

bamboo.buildKey

The job key for the current job, in the form PROJECT-PLAN-JOB, such as BAM-MAIN-JOBX

bamboo.planKey

The key of the current plan, in the form PROJECT-PLAN, such as BAM-MAIN

bamboo.shortPlanKey

The short key of the current plan (without the project part), such as MAIN

bamboo.shortJobKey

The short key of the current job (without the project and plan parts), such as JOBX

bamboo.buildResultKey

The result key when this job executes, in the form PROJECT-PLAN-JOB-BUILD, such as BAM-BOO-JOB1-8, where 8 is the build number. For deployment projects, this variable will not have the JOB component, such as PROJ-TP-6.

bamboo.buildResultsUrl

or

bamboo.resultsUrl

The URL of the result in Bamboo once the job has finished executing.

bamboo.buildNumber

The Bamboo build number, such as 123

bamboo.buildPlanName

The Bamboo job name, such as Some Project name - Some plan name - Some job name

bamboo.planName

The current plan's name, such as Some project name - Some plan name

bamboo.shortPlanName

The current plan's name without the project part, such as Some plan name

bamboo.shortJobName

The current job's name without the project and plan parts, such as Some job name

bamboo.buildTimeStamp

The time when the build was started in ISO 8601 format, such as 2010-01-01T01:00:00.000+01:00

bamboo.agentId

The ID of the agent that the deployment is executed on.

bamboo.agentWorkingDirectory

The path to the working directory on the agent, for example <HOME>/xml-data/build-dir

The agent working directory is not the same as the build working directory described below.

bamboo.build.working.directory

The working directory on which the build is being executed, for example <HOME>/xml-data/build-dir/AV-AVT-JOB1

bamboo.ManualBuildTriggerReason.userName

The user who triggered the manual build

Generic repository variables


bamboo.planRepository.<position>.branchName

The name of the branch in the repository (depends on availability from the VCS used), such as default

bamboo.planRepository.<position>.name

The name of of the repository, as shown in the repository for the plan, such as Mercurial

bamboo.planRepository.<position>.revision

The revision used to build this release. The format depends on the VCS used.

bamboo.planRepository.<position>.previousRevision

The previous revision number (this might not exist, for example for the initial build)

bamboo.planRepository.<position>.type

The type of the repository, as defined by a repository plugin, such as hg, svn, git

Subversion


bamboo.planRepository.<position>.username

The user name, used for repository authentication

bamboo.planRepository.<position>.repositoryUrl

The repository URL

CVS


bamboo.planRepository.<position>.last.update.time

The last updated timestamp

bamboo.planRepository.<position>.last.update.time.label

The last updated timestamp to be used as a label for post-build result labeling. The spaces in the cvs version string are replaced with '_'.

Perforce


bamboo.planRepository.<position>.revision.number

The change set number

bamboo.planRepository.<position>.username

The user name, used for repository authentication

bamboo.planRepository.<position>.port

The port used for repository communication

bamboo.planRepository.<position>.client

The client used for repository communication

Git


bamboo.planRepository.<position>.branch

The branch

bamboo.planRepository.<position>.repositoryUrl

The repository URL

Mercurial


bamboo.planRepository.<position>.repositoryUrl

The repository URL

bamboo.planRepository.<position>.branch

The branch

bamboo.planRepository.<position>.username

The user name, used for repository authentication

  • System variables also apply across your entire Bamboo instance and inherit their values from the system or environment variables of the same name.
  • In the variable names from the table above, <position> is an optional parameter that specifies the position of the repository in the plan's repository list. If omitted, the first repository in the list is used.
  • Third-party repository plugins can expose their own variables.

Build dependency variables

The following build dependency variables are also available:

Build-specific variable

Description

bamboo.dependency.parent.#

Allows a child build to query the build key of the triggering parent build, where # represents the position in the build tree, with 0 at the top, 1 following, and so on. The ${bamboo.dependency.parent.0} variable can be viewed in the child plan's metadata tab.

bamboo.dependency.parent.total

The total number of parent

Deployment variables

Bamboo manages a number of standard reserved variables that are available when deploying a project. 

Variables later in the following list override the previous ones in case of repeating names:

  • Global variables
  • Release variables as defined below
  • User variables defined at the environment level
  • The autogenerated variables in the following table:

Variable

Description

bamboo.agentId

The ID of the agent that the deployment is executed on

bamboo.agentWorkingDirectory

The path to the working directory on the agent. This is not the same as the Bamboo working directory.

bamboo.build.working.directory

The path to the working directory for Bamboo. This is used by both the build plan and the deployment project.

bamboo.deploy.environment

The name of the environment that the release is to be deployed to.

bamboo.deploy.project

The name of the deployment project.

bamboo.deploy.rollback

True if the release being deployed is older than the release being replaced.

bamboo.deploy.release

bamboo.deploy.version

The name of the release that is being deployed. Either .release or .version can be used. Both return the name of the release being deployed.

bamboo.deploy.release.previous

bamboo.deploy.version.previous

The name of the release that is being replaced (if available). Either .release or .version can be used. Both return the name of the release being replaced.

bamboo.resultsUrl

The URL to the screen in Bamboo that displays build results

You can generate variables of your own, using a similar format. However, you cannot create a variable that is already in use by Bamboo. See Defining deployment environment variables for more information.

Releases variables

Bamboo makes the following types of variables available for deployment releases:

  • Snapshots of values for global variables
  • Snapshots of values for plan variables
  • Snapshots of values of repository variables
  • The autogenerated release variables in the following table:

Variable

Description

bamboo.buildNumber

The build result from which the release is created

bamboo.buildResultKey

The key of the build result from which the release is created, such as KUNG-FOO-JOB1-35

bamboo.planKey

The key of the plan related to the release, such as KUNG-FOO

bamboo.planName

The name of the plan related to the release, such as Kung - Foo

bamboo.shortPlanKey

The short key of the plan related to the release (without the project part), such as MAIN

bamboo.shortPlanName

The plan's name without the project part, such as Some plan name

Note:

Several of the variables in the above table are actually those associated with the build plan.

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.

Note:

In older Bamboo versions, using 'PATH' in the Environment Variables field (of a Script task) does not set the windows PATH variable, whereas using 'Path' sets Path and PATH in cmd shell.

Variables in bash

Bamboo variables are exported as bash shell variables. All full stops (periods) are converted to underscores. For example, the variable bamboo.my.variable is $bamboo_my_variable in bash. This is related to File Script tasks (not Inline Script tasks).

Jira application variables

Note:

These variables can be accessed from a Bamboo build only when that build was triggered by  releasing a version in Jira Software Server.

Jira variable

Description

${bamboo.jira.baseUrl}

The URL of your Jira application server

${bamboo.jira.projectKey}

The key of the triggering Jira application project

${bamboo.jira.projectName}

The name of the triggering Jira application project

${bamboo.jira.version}

The release version of the triggering Jira application project

${bamboo.jira.username}

The username of the user who triggered the release build

Examples

Maven examples

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

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

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

Copy
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 examples

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

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

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

Specify 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

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

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

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

    Copy
    ${bamboo.capability.system.p4Executable}

If you click a capability, the specific capability key is contained in the URL.

Note:

The space characters in the URL will be replaced with '+' characters. Consider not using 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.

Use capabilities

Global and Build-Specific Variables can be used in specific fields of your build plan. For capabilities:

  • System Capabilities are available to all of these fields (that is global and build-specific).
  • Agent Capabilities (that is agent-specific and shared/server capabilities) are available only to the build-specific fields (that is not available to Repository URLCVS 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:

  • Set the following as a system environment variable field on the Builder tab:
    ${bamboo.capability.thatsystemvariable}

  • Specify the system environment variable as a custom capability on each of your agents and set the capability to the different values, as desired.

Deprecated variables

The following variables are deprecated and are subject for removal in future Bamboo releases:

Generic repository variables


bamboo.repository.revision.number

The revision number

bamboo.repository.branch.name

The repository branch name (for Bamboo version 4.2 or later)

bamboo.repository.previous.revision.number

The previous revision number (might not exist, for example for the initial build)

Subversion


bamboo.custom.svn.revision.number

The revision number

bamboo.custom.svn.lastchange.revision.number

The last changed revision number

bamboo.custom.svn.username

The user name used for repository authentication

bamboo.repository.svn.repositoryUrl

The repository URL

bamboo.planRepository.<position>.revision.number

The revision number

bamboo.planRepository.<position>.lastchange.revision.number

The last-changed revision number

CVS


bamboo.custom.cvs.last.update.time

The last updated timestamp

bamboo.custom.cvs.last.update.time.label

The last updated timestamp to be used as a label for post-build result labeling. The spaces in the CVS version string are replaced with '_'.

Perforce


bamboo.custom.p4.revision.number

The changeset number

bamboo.custom.p4.username

The user name used for repository authentication

bamboo.custom.p4.port

The port used for repository communication

bamboo.custom.p4.client

The client used for repository communication

Git


bamboo.repository.git.branch

The branch

bamboo.repository.git.repositoryUrl

The repository URL

Mercurial


bamboo.repository.hg.repositoryUrl

The repository URL

bamboo.repository.hg.branch

The branch

bamboo.repository.hg.username

The user name, used for repository authentication