Sub topic 2
Choosing what to re-run: all jobs, failed jobs, or one job
This chapter assumes you know that a workflow run is made of jobs, that jobs can depend on each other with needs, and that each run has a run ID. Here you will learn the three re-run scopes and how to pick one.
The three scopes
When a run finishes with a failure, GitHub gives you three ways to run it again. Each one creates a new run attempt of the same run. The run ID stays the same, and the attempt number goes up by one.
| Scope | What runs again | Typical use |
|---|---|---|
| All jobs | Every job in the workflow | You changed something outside the workflow, or you need a clean run from the start |
| Failed jobs | Each job that failed, plus the jobs that depend on it | A flaky test, a network timeout, a runner problem |
| A single job | The one job you pick, plus the jobs that depend on it | You are investigating one job and want the others left alone |
Jobs that already succeeded are not run again by the failed-jobs and single-job scopes. Their results from the earlier attempt are carried into the new attempt.
Re-run all jobs
Use this scope when you do not trust the earlier results. For example, a job may have succeeded but left a cache in a bad state. A full re-run discards that doubt, because every job starts again.
The cost is time and runner minutes. A pipeline with a 20-minute build and a 2-minute lint step repeats both.
Re-run failed jobs
This is the usual choice. Take a pipeline where build succeeds, test fails, and deploy has needs: test:
buildpassed, so it is not run again.testfailed, so it runs again.deploywas skipped becausetestfailed. It depends ontest, so it runs again in the new attempt iftestnow passes.
Dependent jobs are included because they could not finish properly without the failed job. You do not have to pick them yourself.
Re-run a single job
Choose this when you want to target one job. Open the job and re-run only that one. The jobs that depend on it are re-run too, so a downstream deploy job can still run if the re-run succeeds.
Single-job re-runs help when a run has many independent jobs, such as a matrix. If only the windows-latest leg failed, you can re-run just that leg and leave the other legs alone.
Choosing a scope
A simple rule: start with failed jobs. Move to all jobs only when you have a reason to doubt the passing jobs. Move to a single job when you are working on one problem.
The same scopes from the command line
The gh CLI maps directly to the three scopes. You will see the full CLI and REST API workflow in a later chapter, so this is only a preview.
gh run list --workflow ci.yml --status failure --limit 5
gh run rerun 1234567890
gh run rerun 1234567890 --failed
gh run rerun --job 987654321The first command lists recent failed runs. The second re-runs all jobs of run 1234567890. The third re-runs only the failed jobs. The last one re-runs one job, identified by its job ID instead of the run ID.
Common mistakes
- Mixing up IDs. A run ID identifies the whole run. A job ID identifies one job inside it.
--jobneeds the job ID. - Expecting a clean slate from a failed-jobs re-run. Jobs that passed keep their earlier outputs and artifacts. If a passing job produced bad output, re-running only the failed jobs will not fix it.
- Treating a re-run as proof of a fix. If a job passes on the second attempt, the failure was intermittent. It is not fixed. Look at the logs of the failed attempt before you move on.
Exercise
Exercise
A run has three jobs: lint, test, and deploy. deploy has needs: test. In attempt 1, lint passes, test fails, and deploy is skipped. You use "Re-run failed jobs". Which jobs run in attempt 2, and what happens to the run ID?
Show answer
test runs again because it failed, and deploy runs again because it depends on test. lint is not run again, because it passed, and its result carries over from attempt 1. The run ID stays the same. Only the attempt number changes, from 1 to 2.