Cloud customer?
Start for Free>
Upgrade in MyJFrog >
What's New in Cloud >





You are viewing an old version of this page. View thecurrent version.

Compare with CurrentView Page History

« PreviousVersion 30Next »

Overview

This page describes the availability and usage of environment variables in pipelines.


You can customize your workflow by using environment variables that are available at runtime. For example, your step can construct a filename or build ID from the pipeline name and current run number. Or your step can execute different commands depending on the state of a resource.

JFrog Pipelines provides access to useful internal information from pipelines and resources through environment variables. Pipelines also provides several easy ways to inject your own environment variables into your runtime during the execution of your pipeline.

Page Contents


Standard Environment Variables

These environment variables are available to all executing pipelines.

Environment Variable Description

pipeline_name

Thenamestring of the pipeline currently executing.
run_number The number of the run currently executing.

run_id

Internal unique ID for the run.

step_name

Thenameof the step as specified in YAML.

step_id

Internal unique ID for the step currently executing.

step_type

Thetypeof step as specified in the field in YAML (e.g., "Bash," "DockerBuild," etc.)

step_image_name

Name of the Docker image used to run the step (e.g.pipelines-docker.jfrog.io/jfrog/pipelines-u16node).

step_image_tag

Tag of Docker image used to run the step.

step_node_name

Name of the node used to run step (user-configured when adding node)

architecture

Node architecture, e.g. x86_64

step_node_id

Internal unique ID for node

step_node_pool_name Name of the node pool used to run the step (user configured when creating pool)
project_name Name of the project
project_id ID of the project in JFrog Pipelines
project_key Project key. If the project is the default project, this will be empty.

step_url

Direct link to step

pipelines_api_url

API URL

current_script_section

onStart/onExecute/onComplete etc

operating_system

OS where step is running, e.g. Ubuntu_16.04

step_platform

Same asoperating system.

builder_api_token

Token used to call pipelines API during step execution. Used internally but is accessible to user.

step_triggered_by_resource_name

If triggered by a resource, thenameof the resource. Otherwise, this environment variable is empty.

step_triggered_by_step_name

If triggered by another step, name of step. Else empty

step_triggered_by_identity_name

If triggered by a user, name of user. Else empty

step_affinity_group

Affinity group step belongs to. Default is same as step name.

step_<inputStepName>_statusName

This environment variable is automatically made available at runtime and can be used in any step.inputStepNameis the name of your input step.This environment variable is useful for fetching the status of any input step.
For an example, seeusingstep__statusName.

running_in_container

True if step is running in a container. False if running on host.

step_runtime

Set to "image" or "host"

shared_workspace The path of a directory available to all steps in anaffinity groupthat may be used to share files between steps.
JFROG_CLI_BUILD_NAME If not set as a variable in the YML or added as a pipeline, run, or step variable, it will be set to $pipeline_name. This is used when accumulating build info.
JFROG_CLI_BUILD_NUMBER If not set as a variable in the YML or added as a pipeline, run, or step variable, it will be set to $run_number. This is used when accumulating build info.
JFROG_CLI_BUILD_PROJECT If not set as a variable in the YML or added as a pipeline, run, or step variable, it will be set to $project_key. This is used when accumulating or publishing build info.

路径

The value of PATH in the currently executing runtime environment.


User-defined Environment Variables

User-defined environment variables are custom variables that can be defined intheconfigurationsection of your pipelines YAML file.

Pipelines

In a pipeline, environment variables can be declared within theconfigurationsection.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 theconfigurationsection 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

当宣布环境变量时,导入ant 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.引用所需的字符串:

  • 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)

Examples

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:

  • \nis used to represent a new line
  • \tis used to represent a tab
  • \\is used to represent the 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\ninto 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.

Environment Variables Configuration

Besides the key-value syntax, the following properties can also be used under an environment variable definition to enhance its configuration:

Property Description Required/Optional
default Default value for the environment variable. Required

description Describes the environment variable usage. This description is displayed in thecustom run configuration panel. Optional
values List of values that can be assigned to environment variables whencustom run configuration is used in the UI. Optional
allowCustom Determines if users are allowed to use a custom value that is not part of the list ofvalues. Default value isfalse. Optional

The followingproperties are available for environment variables declared in bothpipelinesandstepsconfigurationsections.

pipelines: - name: my_pipeline configuration: environmentVariables: readOnly: env1: value1 env2: default: value1 description: env2 description values: - value1 - value2 - value3 steps: - name: my_step type: Bash configuration: environmentVariables: step_env1: default: value1 description: step env1 description values: - value1 - value2 - value3 allowCustom: true step_env2: value2 execution: onExecute: - echo "test"

When youtrigger a run with custom configuration, the UI uses the configurations in the YAML file to control user input in theRun With Custom Configurationpanel:

In the YAML, ifallowCustomis set astrue, you can enter any value for that fieldto define your own value for the run. In the example above, you can enter a custom value forstep_env2, in addition to the values that are already defined. Note that the custom value is available for a specific run only.


Integrations

A step that uses an integration can access an integration's properties through environment variables. The form of the environment variable is:

int__

For example, you can access the URL property of anArtifactory IntegrationnamedmyArtifactorythrough an environment variable:

$ printenv int_myArtifactory_url https://mycompany.com/artifactory/

You can also access the properties of an integration through a resource that uses it. The form of the environment variable is:

res___

For example, anImageresource specifies an Artifactory integration in itsregistrytag. You can access the URL of the Artifactory integration used by an Image resource calledmyImageas follows:

$ printenv res_myImage_registry_url https://mycompany.com/artifactory/

For more information, seePipelines Integrations.


2022世界杯阿根廷预选赛赛程

A step that specifies a resource ininputresourcescan access the properties of that resource through environment variables. The form of the environment variable is:

res__

For example, you can access theimageNameproperty of anImageresourcemyImagethrough an environment variable:

$ printenv res_myImage_imageName jfrog.local:5000/alpine37

Some resources maintain additional properties that may be accessed as environment variables. These resource types include:

For further information seePipelines Resources.

Resource-based State

此外,您可以添加您自己的属性resource that is specified inoutputresourcesusing thewrite_outpututility function. This can be used to createstateful pipelines.

The newly attached properties can be accessed as environment variables of the formres_{Resource Name}_{Key Name}.For example, the following creates three properties in the resourcemyImage.

write_output myImage sport="baseball" equipment="bat" field="diamond"

When the resource is specified in a step'sinputsources, these properties can be accessed as the following environment variables:

$ printenv res_myImage_baseball baseball $ printenv res_myImage_equipment bat $ printenv res_myImage_field diamond

For more information on run state, seeCreating Stateful Pipelines.


Run State

Your pipeline can define its own environment variables and add them to the pipeline's run state. These will be available to all steps in the run of the pipeline.

Use theutility functions for run state managementto add new environment variables to the current run state. For example, the following line in the execution block of a step:

add_run_variables hero="Superman" villain="Lex Luthor"

will create two environment variables available to the current and all future steps of the pipeline's run:

$ printenv hero Superman $ printenv villain Lex Luthor

For more information on run state, seeCreating Stateful Pipelines.


Pipeline State

Your pipeline can define its own environment variables and add them to the pipeline state. These will be available to all runs of that pipeline.

Use theutility functions for pipeline state managementto add new environment variables to the current run state. For example, the following line in the execution block of a step:

add_pipeline_variables animal="dog" vegetable="carrot"

will create two environment variables available to all run of the pipeline where they were defined:

$ printenv animal dog $ printenv vegetable carrot

For more information on pipeline state, seeCreating Stateful Pipelines.


  • No labels
Copyright © 2023 JFrog Ltd.