How to use Backslashes in Injected Variables

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問



目的

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.

ソリューション

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: \\.

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

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

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

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:

echo "${bamboo.inject.test3}"

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

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



最終更新日: 2019 年 10 月 7 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.