How do I use the timeout section in a pipeline as code?

Modified on Wed, 21 Jun 2023 at 03:21 PM

The timeout section in a pipeline as code allows you to set a maximum execution time for a specific job in your GitLab pipeline. If the job exceeds the specified timeout value, it will be terminated, preventing it from running indefinitely and potentially causing delays in your pipeline.


Here's how you can use the timeout section in your pipeline as code:


job1:
  script:
    - echo "Job 1"
  timeout: 30 minutes

job2:
  script:
    - echo "Job 2"
  timeout:
    duration: 1h30m
    action: cancel


In the above example:


job1 has a timeout of 30 minutes specified as a simple duration value. If the job runs for longer than 30 minutes, it will be automatically terminated.

job2 has a more complex timeout configuration. The duration field specifies a timeout of 1 hour and 30 minutes. The action field is set to "cancel", which means that if the job exceeds the timeout, it will be canceled immediately.

You can customize the timeout duration based on your job requirements. The timeout value can be specified in minutes, hours, or a combination of both. Additionally, you can choose different actions to take when a timeout occurs, such as canceling the job, failing the job, or allowing it to continue.


Using the timeout section, you can ensure that jobs in your pipeline have a defined maximum execution time, preventing them from running indefinitely and allowing your pipeline to progress smoothly.


Remember to consider the nature of your jobs and their resource requirements when setting the timeout value. Setting it too low may cause premature termination of jobs, while setting it too high may result in longer wait times for failed or hung jobs.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article