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
trueorfalse, so compare with== truenot a shell test.
Related guides
How to Print the Full Context With toJSON in GitHub ActionsDump an entire GitHub Actions context (github, env, job, steps, runner) to the log with toJSON so you can see…
How to Debug a Skipped Job by Checking the if Condition in GitHub ActionsFigure out why a GitHub Actions job shows up as skipped by inspecting its if condition and needs results, the…