AI Hints
Home›CI/CD with GitHub Actions Tutorial›Debugging, Speed, and Cost
CI/CD with GitHub Actions · Lesson 112 of 138

Debugging Workflows

When CI is confusing.

⏱ 2 min read▶ Video at 2:10:47🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Sometimes a workflow does something you didn't expect, and the log doesn't say why. A few simple tricks make the invisible visible. Print things, trace commands, and turn on debug logging.

Debugging Workflows
From the video: Debugging Workflows
  • Unexpected behaviour
  • Logs don't say why
  • Make it visible

Tracing a step

Set dash X makes bash print each command before running it, with a plus sign. So the log shows exactly what ran, after every variable was filled in. Here we can see the ls, the Python version, and the git ref variables.

Terminal
run-steps .github/workflows/debug.yml | grep -vE "^Workflow|^Job|Job succ"
  ✓ Show what is going on
      + ls requirements.txt
      requirements.txt
      + python3 --version
      Python 3.12.3
      + grep '^GITHUB_REF'
      + env
      GITHUB_REF_TYPE=branch
      GITHUB_REF=refs/heads/main
      GITHUB_REF_NAME=main

More debugging tools

Add a secret called actions step debug, set to true, to get very detailed logs. Rerun a failed job with debug logging, from the run page. Print contexts with to JSON, like to JSON of github, to see every value. And actionlint catches many mistakes before you even push.

keyvalue
ACTIONS_STEP_DEBUGvery detailed logs
Re-run with debugfrom the run page
toJSON(github)see all values
actionlintbefore you push

Summary

Trace with set dash X, print contexts, and turn on debug logs. Most mysteries disappear once you can see them. Next, making pipelines faster.

Key takeaways
  • set -x
  • toJSON(github)
  • ACTIONS_STEP_DEBUG
Next up: Speeding Up Pipelines — every minute counts