Advanced Usage of Resources

JFrog Pipelines Documentation

ft:sourceType
Paligo

In a pipeline, the role of a resource goes beyond inputs and outputs. Here are several other ways in which you can use resources in your pipeline.

Using Resources Values in Environment Variables

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

    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>

Using Stateful Resources

Resources are stateful entities and persist across pipelines, enabling passing of information between pipelines. This is especially useful when creating a pipeline of pipelines.

Steps can store any key-value pair data in a resource using the write_outpututility function. These values can then be referenced as environment variables by any subsequent cuting step that uses that resource as an input. Therefore, a step can pass information to another step in the run of the pipeline.

The environment variable for the stored value is of the form res_<resource name>_<key name>.

Example

The following example creates three properties in the resource myImage.

Using write_output

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

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

Environment Variables

$ printenv res_myImage_sport
baseball
$ printenv res_myImage_equipment
bat
$ printenv res_myImage_field
diamond

For more information, see Creating Stateful Pipelines.

Using Extension Resources

Extension resources enable Pipelines users to extend the Pipelines DSL by specifying their own resource types. After an extension resource is loaded, it can be used by any step in a pipeline. For more information, see Pipelines Extension Resource Model.