Skip to main content
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.

Sample Pipeline Without Timeout

Here’s a basic pipeline that deploys an application but uses a sleep 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 the timeout 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 your deploy-job to be canceled after 10 seconds, add timeout: 10s:
When the job exceeds 10 seconds, the runner will terminate it and you’ll see:

Final Pipeline Configuration

Below is the complete pipeline configured with a 10-second timeout for deploy-job:
Choose a timeout value that aligns with your job’s expected duration to maintain pipeline reliability and resource efficiency.

Watch Video