In this guide, you’ll learn how to set a job-level timeout in GitLab CI/CD. Long-running or stalled jobs—caused by script errors, network issues, or unresolved dependencies—can block pipelines and consume resources. By defining a timeout, any job that exceeds the allotted time is automatically terminated.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Sample Pipeline Without Timeout
Here’s a basic pipeline that deploys an application but uses asleep command to simulate a long-running step:
A stalled or infinite loop in
script can cause your pipeline to hang. Always test long-running commands locally before adding them to CI.Why Use Job-Level Timeouts?
- Prevent rogue or hung jobs from consuming runner resources
- Ensure faster pipeline feedback and fail-fast behavior
- Avoid billing surprises on shared or cloud runners
Defining too-short a timeout may lead to unexpected job failures. Choose a duration that accommodates normal execution time plus a buffer.
Adding a Timeout to a Job
To configure a timeout, add thetimeout keyword to any job. GitLab supports human-readable durations in a variety of formats:
Supported Duration Formats
| Format | Examples |
|---|---|
| Hours and minutes | 3 hours 30 minutes |
| Compact (h/m/s) | 3h30m, 45m, 10s |
| Full words | 1 hour, 90 seconds |
| Combined units | 1h 15m, 2h5m30s |
Example: Forcing a Fast Failure
If you want yourdeploy-job to be canceled after 10 seconds, add timeout: 10s:
Final Pipeline Configuration
Below is the complete pipeline configured with a 10-second timeout fordeploy-job: