How to Retry a Failing Task in Azure Pipelines
Azure Pipelines re-runs a failing step automatically with retryCountOnTaskFailure.
Add retryCountOnTaskFailure to a task: or script: step. Azure re-runs that step up to that many times on failure.
Retry a flaky step
This step is retried up to twice on failure before the job is marked failed.
azure-pipelines.yml
steps:
- script: npm run test:integration
displayName: Integration tests
retryCountOnTaskFailure: 2Gotchas
retryCountOnTaskFailureretries only that step; it does not re-run the whole job.- It retries on any failure - do not put it on test steps where a real failure should stop the run.
- There is no built-in backoff; for delay-and-retry on a single command, script a bash loop instead.
Verify it actually works
- Trigger the real event rather than a manual run. Manual dispatch populates a different context, so behaviour depending on the event will differ.
- Assert on the outcome, not on the step exiting zero. Many steps report success while producing nothing.
- Check it on a fresh runner with a cold cache once, so you are not testing warm state that will not exist on the next contributor machine.
Frequently asked questions
How do I retry a Failing Task in Azure Pipelines?
Add retryCountOnTaskFailure to a task: or script: step. Azure re-runs that step up to that many times on failure.
Retry a flaky step?
This step is retried up to twice on failure before the job is marked failed.
Related guides
How to Run a Matrix Build in Azure PipelinesRun a matrix build in Azure Pipelines with strategy:matrix to fan a job across versions, plus maxParallel and
How to Use Conditions and Expressions in Azure PipelinesControl when stages, jobs, and steps run in Azure Pipelines with condition expressions - succeeded, eq, and,