Skip to content
shellhacks.dev
DevOps

Print an Error Annotation in a GitHub Actions Workflow

Print an annotation from a workflow step with an echo of a line starting with ::error, including file, line and title. It does not fail the step on its own.

2 min read
Summarize in AI

A step finds a problem in a file and you want it shown on the pull request next to the line, not buried in the log.

YAML
steps:
  - name: Lint
    run: |
      echo "::error file=app.sh,line=3,title=Lint::Unquoted variable"
      exit 1
Shell
echo "::error file=app.sh,line=3,title=Lint::Unquoted variable"
echo "exit status of the step so far: $?"
echo "::warning::slow test, 4.2s"
printf '::error::first line%%0Asecond line\n'
Text
::error file=app.sh,line=3,title=Lint::Unquoted variable
exit status of the step so far: 0
::warning::slow test, 4.2s
::error::first line%0Asecond line

The runner reads the log of every step, and a line that starts with ::error, followed by parameters and :: and a message, becomes an annotation. The parameters file, line and title place it on the code. A multi-line message uses %0A for the newline, as the last line of the run shows. The second line shows the catch: after printing the annotation the shell status was still 0, so the step passed. See Workflow commands.

To fail the job, end the step with exit 1; the annotation alone only marks the run. GitHub shows a limited number of annotations per step, so a tool with hundreds of findings is better served by a report. Messages are not escaped for you, and a percent sign in the text has to be written as %25.

Share

More snippets

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.