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

Modified on Wed, 21 Jun 2023 at 04:36 PM

The retry section in a pipeline as code allows you to configure retry logic for a specific job in case of failures. It provides a way to automatically retry a job a certain number of times before considering it as failed. This can be helpful in scenarios where transient issues or temporary failures might occur during the job execution.


To use the retry section in your pipeline as code, follow these steps:


Define the job you want to retry in your pipeline YAML file. For example:


stages:
  - build

job1:
  stage: build
  script:
    - echo "Running the job..."
  retry:
    max: 3
    when:
      - runner_system_failure
      - stuck_or_timeout_failure


Specify the retry section within the job definition and configure its properties. In the example above, the retry section is set with a maximum of 3 retries.


Optionally, you can specify the when condition under the retry section to specify the failure types that should trigger a retry. In this case, the job will be retried when there is a runner system failure or a stuck or timeout failure.


Here's an example of a complete pipeline YAML file that includes the retry section:


stages:
  - build

job1:
  stage: build
  script:
    - echo "Running the job..."
  retry:
    max: 3
  when: always


In this example, the job1 will be retried up to 3 times if it fails. It will be retried regardless of the failure reason since the when condition is set to always.


By using the retry section, you can configure a job to automatically retry a certain number of times in case of failures. This helps improve the robustness and reliability of your pipeline, allowing it to recover from transient issues or temporary failures.

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