Skip to content
Latchkey

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: 2

Gotchas

  • retryCountOnTaskFailure retries 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

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card