How to use Backslashes in Injected Variables

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

When backslashes are used in Bamboo variables created using the Inject Variables Plugin, they may be omitted from the output, or cause issues with adjacent characters. This article will show how backslashes can be used in such variables.

Solution

As this Plugin reads the variables using Java libraries, certain characters need to be escaped

There are two groups of characters that need to be escaped:

  1. Letters that, when following a backslash, create an escape sequence

  2. Other special characters

Escape Sequences

Escape sequences require a total of 6 backslashes to properly escape them. This is because of the different layers of escaping that need to happen:

  1. When injected from the file into Bamboo itself; and

  2. In variable replacement.

These Escape sequences include (but may not be limited to):

  • \a - Alert/Bell character

  • \b - Backspace

  • \f - Form feed

  • \n - Newline

  • \t - (Horizontal) Tab

  • \u - Unicode character marker

  • \v - Vertical tab

  • \x - Hexadecimal marker

Other special characters

Other special characters, including the backslash, only need one backslash to escape them, as follows: \\.

Example

For example, I have a sample variable inject file that contains this variable:

1 test3=this\\is\\\\\\a\\\\\\test

Once the variable file is processed, after the first round of escaping, we see the following in the log:

1 command 21-Jun-2017 15:48:57 Substituting variable: ${bamboo.inject.test3} with this\is\\\a\\\test

When the Variable is used in a Script task, for example:

1 echo "${bamboo.inject.test3}"

The output, after the second and final escaping process, is:

1 build 21-Jun-2017 15:48:57 this\is\a\test

Updated on April 2, 2025

Still need help?

The Atlassian Community is here for you.