Is there a way to configure retries for Azure DevOps pipeline tasks or jobs?

Viewed 2538

Currently I have a OneBranch DevOps pipeline that fails every now and then while restoring packages. Usually it fails because of some transient error like a socket exception or timeout. Re-trying the job usually fixes the issue.

Is there a way to configure a job or task to retry?

2 Answers

Update:

Automatic retries for a task was added and when you read this it should be available for usage.

It can be used as follow:

- task: <name of task>
   retryCountOnTaskFailure: <max number of retries>
   ...

Here are a few things to note when using retries:

  • The failing task is retried immediately.
  • There is no assumption about the idempotency of the task. If the task has side-effects (for instance, if it created an external resource partially), then it may fail the second time it is run.
  • There is no information about the retry count made available to the task.
  • A warning is added to the task logs indicating that it has failed before it is retried.
  • All of the attempts to retry a task are shown in the UI as part of the same task node.

Original answer:

There is no way of doing that with native tasks. However, if you can script then you can put such logic inside.

You could do this for instance in this way:

n=0
until [ "$n" -ge 5 ]
do
   command && break  # substitute your command here
   n=$((n+1)) 
   sleep 15
done

However there is no native way of doing this for regular tasks.

Automatically retry a task in on roadmap so it could change in near future.

enter image description here

Related