timeout-minutes option in GitHub Actions to prevent jobs or steps from running indefinitely. By setting timeouts, you safeguard your CI/CD pipelines from unexpected delays and control your billable minutes.
Why Enforce Timeouts?
- Prevent runaway workflows that consume unnecessary resources
- Control billing by limiting how long jobs or steps can execute
- Fail fast when something goes wrong (e.g., infinite loops or stalled processes)
By default, GitHub Actions will cancel any workflow that runs longer than 360 minutes (6 hours). Configuring
timeout-minutes at a finer granularity helps you catch issues earlier.The Problem: Unbounded Workflow Runs
Imagine you accidentally set asleep duration too high:
Adding a Timeout
You can applytimeout-minutes at two levels:
| Scope | Applies To | Syntax Location | Use Case |
|---|---|---|---|
| Step-Level | A single run or action | Within a steps: | Limit a long-running command or action |
| Job-Level | All steps in a job | Within the job: | Enforce a total time budget per job |
Step-Level Timeout
Limit just the problematic step to, for example, 1 minute:Docker Run step exceeds 1 minute, it is automatically canceled and the job fails.
Job-Level Timeout
Apply a timeout for the entire job — all steps must finish before the deadline:deploy takes longer than 5 minutes in total, the workflow stops.
Setting overly aggressive timeouts may cause legitimate tasks to fail. Choose values that balance reliability and cost control.
Demo and Logs
After committing your changes, trigger the workflow manually. You’ll see:The action has timed out.Logs show the step ran for roughly 1 minute and then terminated at the
timeout-minutes threshold.
Best Practices
- Use step-level timeouts for known long-running commands.
- Apply job-level timeouts to guard entire workflows.
- Monitor execution times and adjust
timeout-minutesas your builds evolve.