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
For more details, see GitLab CI/CD Timeout Settings.
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: