Use Resources Values in Environment Variables

JFrog Pipelines Documentation

ft:sourceType
Paligo

A step that specifies a resource can access the resource and its attributes through environment variables.

  • These environment variables have a standard naming convention: res_<resource name>_<tag>

  • This can be extended further to access an integration that is specified in the resource: res_<resource_name>_<integration tag name>_<tag>

Example

  • If the definition of a GitRepo resource named app_gitrepo is as follows:

    GitRepo Resource Definition

    resources:
      - name: app_gitRepo
        type: GitRepo
        configuration:
          path: user1/repo1
          gitProvider: myGitProvider
  • The environment variable definition would be as follows:

    Environment Variable

    Result

    Description

    res_app_gitRepo_path

    user1/repo1

    Returns the path attribute of the app_gitRepo resource

    res_app_gitRepo_gitProvider_url

    Returns url of the Git Provider of the app_gitRepo resource

  • Then the following environment variables will be available to a step that uses the app_gitRepo resource as an input:

    Environment Variables

    steps:
      - name: build_app
        type: MvnBuild
        configuration:
          sourceLocation: .
          mvnCommand: clean install
          configFileLocation: .
          inputResources:
            - name: app_gitRepo             # Use the app_gitRepo resource
       execution:
         onSuccess:
           - send_notification notifySlack --text "Maven build completed for $res_app_gitRepo_path at $res_app_gitRepo_gitProvider_url"
         onFailure:
           - send_notification notifySlack --text "Maven build FAILED for $res_app_gitRepo_path at $res_app_gitRepo_gitProvider_url"
Using Arrays

Certain resources, such as Aql, DistributionRule, and VmCluster have arrays in their configuration.

res_<resource name>_<array heading>_len (this tells you how many entries in array)

res_<resource name>_<array heading>_0

res_<resource name>_<array heading>_1

res_<resource name>_<array heading>_2

res_<resource name>_<array heading>_len (this tells you how many entries in array)

res_<resource name>_<array heading>_0_<tag>

res_<resource name>_<array heading>_1_<tag>