Retry a job multiple times

Is there a way to retry a passed or failed job for more than once?

  • When tried from UI, I am able to retry a job by clicking retry button once but the button disappears after that. The API POST /projects/:id/jobs/:job_id/retry allows us to retry a job once but on second attempt with same project id and job id, it throws error “gitlab service doesn’t allow the action on this resource”. Is there any setting or configuration we can apply to enable retry feature multiple times?

Hi @pravin.salgaonkar

In your .gitlab-ci.yml you want something like this:

run
     stage: run
     image: ruby:2.7
     before_script:
         - bundle install --path vendor/bundle
     script:
         - bundle exec ...
     retry: 2

to retry the job twice. There are docs for retry here.

Cheers,

Sarah

thanks @snim2 for the reply.
Instead of just 2, can we specify some value to “retry” so that Job can be retry multiple times?

Yes; the 2 means that the job will be retried at most twice, but you could use any number (or presumably a variable)