User-defined Environment Variables

JFrog Pipelines Documentation

Products
JFrog Pipelines
Content Type
User Guide
ft:sourceType
Paligo

User-defined environment variables are custom variables that can be defined in the configuration section of your pipelines YAML file.

Pipelines

In a pipeline, environment variables can be declared within the configuration section. The environment variables declared here are available to all steps in the pipeline.

pipelines:
  - name:       my_pipeline
    configuration:
      environmentVariables:
        readOnly:
          env1:     value1
          env2:     value2

Steps

In a step, environment variables can be declared within the configuration section of the step within a pipeline. The environment variables from this source are available only to the step where they are declared.

    steps:
      - name:       step_1
        type:       Bash
        configuration:
          environmentVariables:
            env1:     value1
            env2:     value2

YAML Schema Reference

When declaring environment variables, it is important to follow YAML syntax conventions and properly quote and escape values to ensure that Pipelines can parse them correctly.

In general, YAML strings are Unicode and can be left unquoted. However, certain rules apply when using special characters. Quotes are required for strings that:

  • Start with a special character, such as: :, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, )

  • Start or end with whitespace characters

  • Look like a number or boolean (123, 1.23, true, false, null)

Example

Single Quotes

Example

Result

Comments

'This string 'uses single quotes''

This string 'uses single quotes'

  • Single quotes let you include almost any character in your string.

  • Single quotes will not parse escape codes. For example: "\n" is returned as the string \n.

  • Use two single quotes ('') to include a single quote inside the single-quoted string.

'This string "uses double quotes"'

This string "uses double quotes"

'& this string starts with a special character, needs quotes'

'& this starts with a special character, needs quotes'

Double Quotes

Example

Result

Comments

"This string \nis on the next line"

This string

is on the next line

Double quotes support any character string and escape sequences.

For example: \n, \\, and \")

"This string uses \ttab"

This string uses tab

Multi-line Strings

Multi-line strings can be written using:

  • Folded Style: Represented by a greater than symbol (>), where each line break is converted to a space.

  • Literal Style: Represented by a pipe (|), to preserve line breaks.

Folded Style (>)

Example

Result

Comments

foo: >

This is a string.

Another string.

One more.

This is a string. Another one. One more.

Folded style removes end of line characters and replaces double end of lines with single lines. This is useful for descriptions.

  • Use >- if you do not want a line-break appended at the end.

  • Use >+ if you want a line-break appended at the end.

execution:

onExecute:

- >

echo "hello"

echo "world"

hello world

Literal Style (|)

Example

Result

Comments

foo: |

This is the first line.

This is the second line.

This is the third line.

This is the first line.

This is the second line.

This is the third line.

Literal style preserves end of line characters. This is useful when defining script actions.

  • Use | - if you do not want a line-break appended at the end.

  • Use | + if you want a line-break appended at the end.

execution:

onExecute:

- |

echo "hello"

echo "world"

hello

world

Escape Sequences

YAML uses escape sequences as follows:

  • \n is used to represent a new line

  • \t is used to represent a tab

  • \\ is used to represent a slash

  • Bash style "\ " is used to escape additional spaces that are part of the content and should not be folded

  • The trailing \ is used to represent a continuation marker. This is useful for breaking a long string into multiple lines without introducing unwanted whitespace

Example

Result

Comments

'price: \$10'

price: $10

Special characters must be escaped with backslash.

'This string has internal \`back ticks\`'

This string has internal `back ticks`

Backticks must be escaped as they are treated specially by the shell.

'This string has a backslash \\ character'

This string has a backslash \ character

"This string has \$ several ' special \" characters \\ that are\nescaped as necessary"

This string has $ several ' special " characters \ that are escaped as necessary"

In this example:

  • The double quotes enclose the full string. This is done to take advantage of YAML expanding the \n into a newline character.

  • Except for the single quote character, everything else is escaped using backslash.

  • Single quote is treated as a character and does not need escaping.