Start Building for Free

Pipeline values and parameters

1 month ago4 min read
Server v4.x
Server v3.x
On This Page

Pipeline values and parameters can be used to create reusable pipeline configurations.

  • Pipeline values represent pipeline metadata that can be used throughout the configuration.
  • Pipeline parameters are typed pipeline variables that are declared in the parameters key at the top level of a configuration. Users can pass parameters into their pipelines when triggering a new run of a pipeline through the API.

Pipeline values

Pipeline values are available to all pipeline configurations and can be used without previous declaration.

For a full list of values and built-in environment variables, see the Project Values and Variables guide.

pipeline.idStringA globally unique id representing for the pipeline
pipeline.numberIntegerA project unique integer id for the pipeline
pipeline.project.git_urlStringThe URL where the current project is hosted. For example,
pipeline.project.typeStringThe lower-case name of the VCS provider, E.g. “github”, “bitbucket”.
pipeline.git.tagStringThe name of the git tag that was pushed to trigger the pipeline. If the pipeline was not triggered by a tag, then this is the empty string.
pipeline.git.branchStringThe name of the git branch that was pushed to trigger the pipeline.
pipeline.git.revisionStringThe long (40-character) git SHA that is being built.
pipeline.git.base_revisionStringThe long (40-character) git SHA of the build prior to the one being built. Note: While in most cases pipeline.git.base_revision will be the SHA of the pipeline that ran before your currently running pipeline, there are some caveats. When the build is the first build for a branch, the variable will not be present. In addition, if the build was triggered via the API, the variable will not be present.
pipeline.in_setupBooleanTrue if the pipeline is in the setup phase, i.e. running a setup workflow.
pipeline.trigger_sourceStringThe source that triggers the pipeline, current values are webhook, api, scheduled_pipeline
pipeline.schedule.nameStringThe name of the schedule if it is a scheduled pipeline. Value will be empty string if the pipeline is triggerd by other sources
pipeline.schedule.idStringThe unique id of the schedule if it is a scheduled pipeline. Value will be empty string if the pipeline is triggerd by other sources

Usage example:

version: 2.1

      - image: cimg/node:17.0
          username: mydockerhub-user
          password: $DOCKERHUB_PASSWORD  # context / project UI env-var reference
      CIRCLE_COMPARE_URL: << pipeline.project.git_url >>/compare/<< pipeline.git.base_revision >>..<<pipeline.git.revision>>
    working_directory: ~/main
      - run: echo "This is pipeline ID << >>"
      - run: echo $CIRCLE_COMPARE_URL

When using the above method to set the values in the environment key, note that if the pipeline variable is empty it will be set to <nil>. If you need an empty string instead, set the variable in a shell command. {class=”alert alert-info” }

Pipeline parameters in configuration

Pipeline parameters are declared using the parameters key at the top level of a .circleci/config.yml file.

Pipeline parameters support the following types:

  • string
  • boolean
  • integer
  • enum

See Parameter Syntax for usage details.

Pipeline parameters can be referenced by value and used as a config variable under the scope pipeline.parameters.

The example below shows a configuration with two pipeline parameters (image-tag and workingdir) defined at the top of the config, and then subsequently referenced in the build job:

version: 2.1
    type: string
    default: "current"
    type: string
    default: "~/main"

      - image: cimg/node:<< pipeline.parameters.image-tag >>
          username: mydockerhub-user
          password: $DOCKERHUB_PASSWORD  # context / project UI env-var reference
      IMAGETAG: << pipeline.parameters.image-tag >>
    working_directory: << pipeline.parameters.workingdir >>
      - run: echo "Image tag used was ${IMAGETAG}"
      - run: echo "$(pwd) == << pipeline.parameters.workingdir >>"

Passing parameters when triggering pipelines via the API

A pipeline can be triggered with specific parameter values using the API v2 endpoint to trigger a pipeline. This can be done by passing a parameters key in the JSON packet of the POST body.

Note: Please note that the parameters key passed in this POST request is NOT secret.

The example below triggers a pipeline with the parameters described in the above config example (NOTE: To pass a parameter when triggering a pipeline via the API the parameter must be declared in the configuration file.).

curl -u ${CIRCLECI_TOKEN}: -X POST --header "Content-Type: application/json" -d '{
  "parameters": {
    "workingdir": "./myspecialdir",
    "image-tag": "4.8.2"

Passing parameters when triggering pipelines using the CircleCI web app

In addition to using the CLI and API, you can also trigger a pipeline with parameters from the CircleCI web app. To do this:

  1. Navigate to the dashboard view in the web app.
  2. Use the project filter to select the desired project.
  3. Use the branch filter to select the branch on which you want to run the new pipeline.
  4. Click the Trigger Pipeline button (towards the top right corner of the page).
  5. Use the Add Parameters dropdown to specify the type, name, and value of your desired parameters.
  6. Click Trigger Pipeline.

NOTE: If you pass a parameter when triggering a pipeline from the web app, and the parameter has not been declared in the configuration file, the pipeline will fail with the error Unexpected argument(s))

The scope of pipeline parameters

Pipeline parameters can only be resolved in the .circleci/config.yml file in which they are declared. Pipeline parameters are not available in orbs, including orbs declared locally in your config.yml file. This was done because access to the pipeline scope in orbs would break encapsulation and create a hard dependency between the orb and the calling config, potentially jeopardizing determinism and creating a surface area of vulnerability.

Config processing stages and parameter scopes

Processing stages

Configuration processing happens in the following stages:

  • Pipeline parameters are resolved and type-checked
  • Pipeline parameters are replaced in the orb statement
  • Orbs are imported

The remaining configuration is processed, element parameters are resolved, type-checked, and substituted.

Element parameter scope

Element parameters use lexical scoping, so parameters are in scope within the element they are defined in, e.g. a job, a command, or an executor. If an element with parameters calls another element with parameters, like in the example below, the inner element does not inherit the scope of the calling element.

version: 2.1

        type: string
      - run: echo << parameters.message >>

        type: string
      - print:
          message: Printing << parameters.file >>
      - run: cat << parameters.file >>

      - cat-file:
          file: test.txt

Even though the print command is called from the cat-file job, the file parameter would not be in scope inside the print. This ensures that all parameters are always bound to a valid value, and the set of available parameters is always known.

Pipeline value scope

Pipeline values, the pipeline-wide values that are provided by CircleCI (e.g. << pipeline.number >>) are always in scope.

Pipeline parameter scope

Pipeline parameters which are defined in configuration are always in scope, with two exceptions:

  • Pipeline parameters are not in scope for the definition of other pipeline parameters, so they cannot depend on one another.
  • Pipeline parameters are not in scope in the body of orbs, even inline orbs, to prevent data leaks.

Conditional workflows

Use the when clause (or the inverse clause unless) under a workflow declaration, along with a logic statement, to decide whether or not to run that workflow. Logic statements in a when or unless clause should evaluate to a truthy or falsy value.

The most common use of this construct is to use a pipeline parameter as the value, allowing an API trigger to pass that parameter to determine which workflows to run.

Below is an example configuration using the pipeline parameter run_integration_tests to drive whether the workflow integration_tests will run.

version: 2.1

    type: boolean
    default: false

  version: 2
    when: << pipeline.parameters.run_integration_tests >>
      - mytestjob

      - checkout
      - ... # job steps

The example shown above prevents the workflow integration_tests from being triggered unless it is explicitly invoked when the pipeline is triggered with the following in the POST body:

    "parameters": {
        "run_integration_tests": true

The when key accepts any truthy or falsy value, not just pipeline parameters, though pipeline parameters will be the primary use of this feature until more are implemented. when also has an inverse clause unless, which inverts truthiness of the condition.

Help make this document better

This guide, as well as the rest of our docs, are open source and available on GitHub. We welcome your contributions.

Need support?

Our support engineers are available to help with service issues, billing, or account related questions, and can help troubleshoot build configurations. Contact our support engineers by opening a ticket.

You can also visit our support site to find support articles, community forums, and training resources.