Skip to content
Latchkey

How to Debug an Expression by Echoing the Rendered Value in GitHub Actions

Expressions resolve before the shell runs, so echoing one shows the literal value the runner substituted.

Wrap the expression in an echo (or assign it to an env var) so the rendered result lands in the log. This is how you catch an if: that silently evaluates to false.

Steps

  • Add a step that echoes the exact expression you are unsure about.
  • Compare the printed value to what your if: expects.
  • Watch for empty strings, which often mean the context field was null.

Workflow

.github/workflows/ci.yml
steps:
  - name: Inspect expression values
    run: |
      echo "ref      = ${{ github.ref }}"
      echo "ref_name = ${{ github.ref_name }}"
      echo "is_main  = ${{ github.ref == 'refs/heads/main' }}"
      echo "contains = ${{ contains(github.event.head_commit.message, '[skip]') }}"

Gotchas

  • A blank line means the expression rendered an empty string; the underlying context field is probably null for this event.
  • In if: the ${{ }} wrapper is optional, but string comparisons are case sensitive.
  • Booleans render as the literal text true or false, so compare with == true not a shell test.

Related guides

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