Skip to content
Latchkey

How to Run a Step Only if a Condition Is True in GitHub Actions

A step-level if: evaluates an expression and runs the step only when the result is truthy.

Attach if: to the step with a boolean expression. GitHub evaluates it, and any non-empty, non-false result runs the step. The ${{ }} wrapper is optional inside if.

Steps

  • Add if: to the step you want to guard.
  • Write a boolean expression referencing github, env, or steps contexts.
  • Leave other steps unconditional so they always run.

Workflow

.github/workflows/ci.yml
steps:
  - id: check
    run: echo "deploy=true" >> "$GITHUB_OUTPUT"
  - name: Deploy
    if: steps.check.outputs.deploy == 'true'
    run: ./deploy.sh

Gotchas

  • Do not wrap the whole if in extra quotes unless it starts with !, or YAML may mis-parse it.
  • A false condition skips the step; it does not fail it.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →