Skip to main content

Working with Steps

1. Defining Steps

Steps are the individual tasks that run in a job. Each step runs in its own process and can execute commands or actions.

Property Description Values
uses Runs a reusable action from a repository actions/checkout@v4
run Runs shell commands in the runner environment npm install
name Human-readable name for the step Setup Node.js
env Environment variables for the step { NODE_ENV: 'production' }

2. Naming Steps

Each step can be given a descriptive name to improve readability and debugging.

Example: Naming Steps

steps:
  - name: "Checkout code"
    uses: actions/checkout@v4
  - name: "Setup Node.js"
    uses: actions/setup-node@v4

3. Running Shell Commands

The run keyword executes commands in the runner environment.

Example: Running Shell Commands

steps:
  - name: "Install dependencies"
    run: npm install

4. Using Actions

Actions are reusable units of code that can be shared and used in workflows.

Property Description Values
uses Specifies the action to use actions/checkout@v4
with Input parameters for the action { token: ${{ secrets.GITHUB_TOKEN }} }
env Environment variables for the action { GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} }

5. Setting Step Conditions

Conditions control whether a step runs based on the outcome of previous steps.

Property Description Values
if Expression that determines whether to run the step success(), failure(), always()
continue-on-error Allows a step to fail without stopping the job true, false

6. Setting Step Timeout

Timeouts prevent steps from running indefinitely.

Example: Setting Step Timeout

steps:
  - name: "Run long task"
    run: sleep 300
    timeout-minutes: 5

7. Setting Step Shell

Specify the shell to use for running commands.

Property Description Values
shell Shell to use for commands bash, sh, powershell

8. Setting Working Directory

Change the working directory for a step.

Example: Setting Working Directory

steps:
  - name: "Run in subdirectory"
    run: npm test
    working-directory: ./frontend

9. Configuring Step Environment Variables

Environment variables can be set per step to control behavior.

Example: Setting Environment Variables

steps:
  - name: "Build with env"
    run: npm run build
    env:
      NODE_ENV: production
      CI: true

10. Handling Step Failures

Steps can be configured to continue on failure or stop the job.

Property Description Values
continue-on-error Allows a step to fail without stopping the job true, false
if Expression that determines whether to run the step success(), failure(), always()

11. Using Step Outputs

Outputs from one step can be used in subsequent steps.

Example: Using Step Outputs

steps:
  - name: "Get version"
    id: version
    run: echo "version=1.0.0" >> $GITHUB_OUTPUT
  - name: "Use version"
    run: echo "Version is ${{ steps.version.outputs.version }}"

12. Running Steps in Containers

Steps can run inside Docker containers for isolated environments.

Example: Running Steps in Containers

steps:
  - name: "Run in container"
    uses: docker://node:18
    with:
      entrypoint: /bin/bash
      args: -c "npm install"

Was this article helpful?