Understanding context information in the CloudBees platform is key to a successful workflow.
Access contexts using an expression that references a context.
You can use the if
keyword for conditional expressions.
The following table lists the platform context objects and their scopes.
Context object name | Description |
---|---|
|
Information about the workflow run.
Refer to the |
|
Contains variables set in a workflow, job, or step for outputs. Refer to env |
|
Use the expression Used in:
Refer to: Using |
|
Use the |
|
Contains outputs of jobs required for the current job to execute. |
|
Use the For example, to return:
|
|
Contains information about steps run in the current job. Refer to jobs.<job_id>.steps. |
|
Use the |
cloudbees
context
The cloudbees
context contains workflow run information.
Property name | Data type | Description |
---|---|---|
|
Object |
The top-level context. |
|
String |
The REST API name. |
|
String |
A token for authenticating to the CloudBees APIs. |
|
String |
The REST API URL. |
|
String |
The CloudBees platform identifier for a component. |
|
Object |
The webhook payload that triggers a workflow run.
|
|
String |
The name of the event that triggers a workflow run: |
|
String |
The home directory inside the current container; defaults to |
|
String |
The CloudBees platform identifier for the organization. |
|
String |
The path to the registry mirror configuration file. |
|
Number |
A unique number representing each attempt of a specific workflow run. Each run_id may have multiple retry attempts, and this value distinguishes between them while remaining fixed for each individual attempt. |
|
String |
A globally unique identifier assigned to each execution of a workflow. This identifier remains constant for the duration of the run. |
|
Number |
A unique, incrementing value assigned to each workflow run within a component. This value reflects the run sequence for a specific workflow, independent of branches or pull request variations. |
|
Object |
The parent context for the SCM keys. |
|
String |
The name of the repository branch that contains the workflow file. |
|
String |
The SCM provider. Valid values are |
|
String |
The SCM provider host URL; for example, |
|
String |
The branch or tag ref that triggers a workflow run.
For example, a branch or tag ref that is pushed in a workflow with a |
|
String |
The repository path in the format |
|
String |
The URL of the SCM repository. |
|
String |
The commit SHA for the workflow file. |
|
String |
This value should normally be left to pick up the default value of ${{ cloudbees.scm.token }}, which injects the CloudBees workflow run token that uniquely identifies a job run within a workflow, and is used to authenticate that run against CloudBees services. |
|
String |
The default working directory for platform workflows. |
|
String |
This is a CloudBees-maintained version of a component. For workflow trigger events, the patch number is incremented. |
If you do not explicitly specify an SCM personal access token with the necessary permissions when invoking the Check out a Git repository action, the action uses the cloudbees.api.token input to make a call back to the CloudBees platform to request an SCM token (cloudbees.scm.token ) with the necessary permissions.
|
Using file.scm.sha
Expression
Use ${{ file.scm.sha }}
to reference commit-specific container images within workflows and actions. This approach helps ensure consistency between referenced images, avoids tag conflicts, and eliminates the need for manual updates.
Limitations
-
Only the
file.scm.sha
expression is allowed in these fields; full dynamic expressions or outputs from other jobs are not supported. -
Docker image tag values must comply with naming rules:
-
Valid ASCII characters only
-
May include letters, digits, underscores (
_
), periods (.
), and dashes (-
) -
Must not begin with a period or dash
-
Maximum length: 128 characters
-
Benefits
-
Enables actions and images defined in the same repository to coordinate builds without manual tag updates.
-
Supports workflows that build an image in one job and safely consume it in another job within the same workflow.
-
Prevents conflicts between concurrent builds across branches or pull requests.
Example Usage
jobs: build: steps: - name: Checkout source uses: cloudbees-io/checkout - name: Build container image uses: cloudbees-io/kaniko with: destination: example.com/foo:latest-${{ file.scm.sha }} (1) dockerfile: ./Dockerfile context: . test: needs: - build services: self: image: example.com/foo:latest-${{ file.scm.sha }} (2) steps: - name: Run tests run: | curl http://self:8080/health
1 | Uses ${{ file.scm.sha }} to tag the container image with the commit SHA of the workflow file. |
2 | Refers to the same commit-tagged image to ensure consistency with the build job. |