jobs.<job_id>.steps[*].uses

3 minute read

A single workflow job must contain only one of the following execution syntax terms:

Specify an action with uses

Use jobs.<job_id>.steps[*].uses to add an action to run in your step. For more information, refer to CloudBees actions.

You can use an action defined in the same repository as the workflow, a public repository, or in a published Docker container image.

CloudBees strongly recommends that you specify the version with any action you use, to avoid any broken workflows or other unexpected behavior. The version may be in the form of a Git tag, branch name, or commit SHA.

Some actions require inputs that you must set using the with keyword. This information is detailed in the action documentation. Actions are Docker containers (not Dockerfile actions), and you must run the job in a Linux environment.

Example usage

{owner}/{repo}@{ref}

In the following example:

  • The First step uses an action from a public repository with the commit SHA specified.

  • The Second step uses a CloudBees platform action with the major version tag specified.

  • The Third step uses the main branch of a subdirectory in a public GitHub repository.

steps: - name: First step uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 - name: Second step uses: https://github.com/cloudbees-io/kaniko@v1 - name: Third step uses: actions/aws/ec2@main

If the action is in the same repository as the workflow, you must first check out your repository, as in the following example:

jobs: my-job: steps: - name: Check out repository uses: https://github.com/cloudbees-io/checkout@v1 - name: Use local action uses: ./.github/actions/my-action

Action contexts

The platform allows you to invoke actions defined in a repository using their relative path (for example, uses: ./local-action), instead of fetching them from a dedicated repository (such as https://github.com/cloudbees-io/checkout).

Local scan action
Figure 1. Scan 2, highlighted, uses a local child action.

In your workflows, you can also use composite actions that invoke other actions, either from a dedicated GitHub repository or a local relative path.

Composite action
Figure 2. A composite action referring to a different repository is highlighted.

If a composite action refers to another action in the same repository by using a local action link (uses: ./local-action), then the workflow that uses this action fails, unless it also resides in the same repository.

All local references, whether from the workflow or any action it uses, are resolved to the repository where the workflow resides.

Specify a Docker image with uses

Use jobs.<job_id>.steps[*].uses to add a Docker image published on Docker Hub to your step.

docker://{image}:{tag}

In the case of a hosted image:

docker://{host}/{image}:{tag}

Example usage

In the following example:

  • The First step specifies the alpine:3.8 image.

  • The Second step specifies a public Docker image in the Google Container Registry at gcr.io.

jobs: my-job: steps: - name: First step uses: docker://alpine:3.8 - name: Second step uses: docker://gcr.io/cloud-builders/gradle

Specify a private image with uses

Use jobs.<job_id>.steps[*].uses to add an image stored in a private repository to run in your step. To learn more about using private images, refer to:

Example usage

In the following example, an image stored in Amazon Web Services (AWS) Elastic Container Registry (ECR) is added to the step.

jobs: my-job: permissions: scm-token-own: read id-token: write steps: - name: Checkout - uses: https://github.com/cloudbees-io/checkout@v1 - name: Log in to AWS uses: https://github.com/cloudbees-io/configure-aws-credentials@v1 id: aws-login with: aws-region: us-east-1 role-to-assume: {{vars.MY_AWS_ROLE }} role-duration-seconds: "3600" - name: Run AWS CLI commands uses: docker://<AWS_ACCOUNT_ID>.dkr.ecr.<REGION>/<REPOSITORY>:<TAG> #1 run: | aws sts get-caller-identity
1 Replace <AWS_ACCOUNT_ID> with your AWS account ID and <REGION> with your selected AWS region to specify your AWS ECR hostname.