jobs.<job_id>.steps

1 minute read

A job contains a sequence of tasks called steps that are used to execute commands or actions. Steps execute in containers that share the same job workspace directory. Because step commands run in their own containers, any changes to environment variables or other local filesystem directories are not saved as the workflow runs from step to step.

Steps can run the following:

  • A custom command.

  • A CloudBees action in your repository or a public repository.

Example usage

apiVersion: automation.cloudbees.io/v1alpha1 kind: workflow name: Greeting from the Hive on: push: branches: - '**' jobs: my-job: steps: - name: Print a greeting uses: docker://alpine:3.18 shell: sh env: FIRST_WORD: Hello SECOND_WORD: there THIRD_WORD: world run: | echo $FIRST_WORD $SECOND_WORD $THIRD_WORD

Step outputs

Steps can produce outputs that subsequent steps in the same job can consume. To consume an output from a step, you can use the outputs field in the corresponding step’s context as shown in the example below.

Example usage

apiVersion: automation.cloudbees.io/v1alpha1 kind: workflow name: Example on: [push] jobs: my-job: steps: - id: generator name: Generate random string uses: docker://alpine:3.23 run: | cat /dev/urandom | tr -dc A-Za-z0-9 | head -c10 > $CLOUDBEES_OUTPUTS/random-value - name: Print random string uses: docker://alpine:3.23 env: RAND_VALUE: ${{ steps.generator.outputs.random-value }} run: | echo "$RAND_VALUE"

In this example, the first step generates a random string and saves it to the $CLOUDBEES_OUTPUTS/random-value file. The value is then available to subsequent steps as an output using the syntax ${{ steps.<step_id>.outputs.<output_name> }}.