Sub topic 9
Writing debug messages and checking runner.debug
This chapter assumes you can read a workflow YAML file (jobs, steps, run commands) and know how to turn on step debug logging, as covered in the earlier chapters. Here you will write your own debug output and make steps react to debug mode.
Why add debug output to a workflow
Step debug logging (ACTIONS_STEP_DEBUG) makes the runner print extra detail about each step. It does not know what your scripts are doing internally. You can fill that gap by emitting messages that appear only when debug logging is on. That keeps normal logs short and still gives you detail when you re-run a failing job with debug logging.
The ::debug:: workflow command
A workflow command is a line printed to standard output that the runner reads and acts on. The debug command looks like this:
echo "::debug::Cache key is $KEY"The runner treats the text after ::debug:: as a debug message. Its visibility depends on step debug logging:
| Step debug logging | What you see |
|---|---|
| Off | The message is hidden from the log. |
| On | The message appears in the step's log output, marked as debug. |
The command is safe to leave in your workflow permanently. It costs almost nothing when debug logging is off.
The runner.debug context
The runner context describes the machine running the job. Its debug property is the string '1' when debug logging is enabled for the run, and it is not set to '1' otherwise. Compare it as a string:
if: ${{ runner.debug == '1' }}Use this when you want to do more than print a message, such as running an extra diagnostic step that takes time or produces a lot of output.
A complete example
This workflow combines both techniques. It also prints github.run_attempt, so each log shows which attempt you are reading. Attempt numbers were covered in the first chapter of this tutorial.
name: ci
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Show attempt number and emit a debug message
run: |
echo "attempt=${{ github.run_attempt }} triggering_actor=${{ github.triggering_actor }}"
echo "::debug::Shown only when step debug logging is enabled"
- name: Extra diagnostics only in debug mode
if: ${{ runner.debug == '1' }}
run: env | sort | grep '^GITHUB_'Walk through what happens in each case:
- On a normal run, the first step prints the attempt number and actor. The
::debug::line is hidden. The last step is skipped becauserunner.debugis not'1'. - On a re-run with debug logging enabled, the debug message appears. The last step runs and lists every environment variable that starts with
GITHUB_.
Common mistakes
- Comparing to a number. Write
runner.debug == '1'with quotes. Context values are strings. - Expecting
runner.debugto reflect only runner diagnostic logs. It is'1'when either debug logging type is enabled, so do not use it to tell the two types apart. - Printing secrets in your own debug messages. The runner masks registered secrets in logs, but a transformed value (for example a base64 encoding of a secret) may not be masked. Never echo credentials, even in a debug line.
- Putting slow or noisy work in a normal step. Gate it with
if: ${{ runner.debug == '1' }}so ordinary runs stay fast.
Exercise
Exercise
You add echo "::debug::Using node $(node --version)" to a step and re-run a failed job with the "Enable debug logging" option checked. Later, a teammate re-runs it normally and does not see the line. Why, and how would you make a separate step run only in the debug re-run?
Show answer
The ::debug:: message is only shown when step debug logging is enabled, so a normal re-run hides it. To run a separate step only in debug mode, add if: ${{ runner.debug == '1' }} to that step.