Sub topic 1
Workflow runs and run attempts
Every re-run and every debug log in the later chapters hangs off one idea: a run can have several attempts. This chapter explains how GitHub Actions identifies a run and its attempts, and which values stay fixed between attempts.
Prerequisites
This chapter assumes you can do the following:
- Navigate a GitHub repository and open its Actions tab.
- Read a workflow YAML file with
jobs,steps, andneeds. - Run basic shell commands. The GitHub CLI (
gh) is optional but used in one example.
What a workflow run is
A workflow run is one execution of a workflow. An event creates it, such as a push, a pull request, or a manual dispatch. The run holds all the jobs defined in the workflow file, plus their steps, logs, and results.
GitHub gives each run three identifiers, available in the github context:
| Context value | Meaning | Changes on re-run? |
|---|---|---|
| `github.run_id` | Unique ID of the run across the repository | No |
| `github.run_number` | Counter for this workflow, starting at 1 | No |
| `github.run_attempt` | Attempt counter within this run, starting at 1 | Yes, increases by 1 |
The run ID is what the API and the gh CLI use to refer to a run. The run number is the "#42" you see in the Actions list.
What a run attempt is
A run attempt is one pass through the run's jobs. The first execution is attempt 1. When you re-run the workflow, GitHub does not create a new run. It adds attempt 2 to the same run, then attempt 3, and so on.
Each attempt keeps its own job results and logs. In the web interface, the run page has an attempt selector, so you can compare a failed attempt with a later one. From the CLI, you can read a specific attempt:
gh run view 1234567890 --attempt 1
gh run view 1234567890 --attempt 2 --logWhat stays the same and what changes
A re-run repeats the same work on the same code. That is useful for flaky tests and bad infrastructure luck, but it can't pick up fixes you push afterward.
Stays the same across attempts:
- The commit SHA and ref (
github.sha,github.ref). - The workflow file as it was at that commit.
- The event payload that triggered the run.
- The run ID and run number.
Changes between attempts:
github.run_attempt, which increases.github.triggering_actor, which is the person who started this attempt. The originalgithub.actorstays the user who triggered attempt 1.- The runners, which are fresh machines, so nothing on disk carries over from earlier attempts.
- The job results and logs, which are stored per attempt.
If you push a new commit, GitHub starts a new run with a new run ID. That is not a re-run.
Seeing attempt data in a workflow
This workflow prints the values so you can watch them change between attempts:
name: show-attempt
on: [push, workflow_dispatch]
jobs:
inspect:
runs-on: ubuntu-latest
steps:
- name: Print run identifiers
run: |
echo "run_id=${{ github.run_id }}"
echo "run_number=${{ github.run_number }}"
echo "run_attempt=${{ github.run_attempt }}"
echo "actor=${{ github.actor }}"
echo "triggering_actor=${{ github.triggering_actor }}"Push this workflow, then re-run it from the Actions tab. In attempt 2, run_id and run_number match attempt 1, run_attempt is 2, and triggering_actor is whoever clicked re-run.
Limits to know now
- You need write access to the repository to re-run a workflow.
- You can't re-run a run that is older than 30 days.
- A run must have finished before you can re-run it. You can't re-run something still in progress.
- Logs follow your repository's retention settings. After they expire, old attempts show no log output.
The next chapters build on this model. You will choose which jobs an attempt should repeat, and then add debug logging to that attempt.
Exercise
A run has ID 5550001 and run number 12. A teammate re-runs it twice. What are the run ID, run number, and github.run_attempt in the last attempt? Does a push of a new commit change any of these values on the existing run?
Show answer
The run ID is still 5550001, the run number is still 12, and github.run_attempt is 3, because the first execution was attempt 1 and each re-run adds one. Pushing a new commit does not alter the existing run. It creates a separate new run with a new run ID and a new run number, and its first attempt is 1.