Cloud customer?
 Upgrade in MyJFrog >

Search





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 VariableDescription

pipeline_name

The name string of the pipeline currently executing.
run_numberThe number of the run currently executing.

run_id

Internal unique ID for the run.

step_name

The name of the step as specified in YAML.

step_id

Internal unique ID for the step currently executing.

step_type

The type of 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_nameName of the node pool used to run the step (user configured when creating pool)

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 as operating 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, the name of 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.

running_in_container

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

step_runtime

Set to "image" or "host"

JFROG_CLI_BUILD_NAMEIf 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_NUMBERIf 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.

PATH

The value of PATH in the currently executing runtime environment.


Pipelines

A pipeline can declare environment variables in its configuration.  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

A step can declare environment variables in its configuration of a 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

Integrations

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

int_<integration name>_<tag>

For example, you can access the URL property of an Artifactory Integration named myArtifactory through 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_<resource_name>_<integration tag name>_<tag>

For example, an Image resource specifies an Artifactory integration in its registry tag.  You can access the URL of the Artifactory integration used by an Image resource called myImage as follows:

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

For more information, see Pipelines Integrations.


Resources

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

res_<resource name>_<tag>

For example, you can access the imageName property of an Image resource myImage through 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 see Pipelines Resources.

Resource-based State

Additionally, you can add your own properties to a resource that is specified in outputresources using the write_output utility function. This can be used to create stateful pipelines.

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

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

When the resource is specified in a step's inputsources, 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, see Creating 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 the utility functions for run state management to 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, see Creating 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 the utility functions for pipeline state management to 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, see Creating Stateful Pipelines.


Copyright © 2021 JFrog Ltd.