'Azure pipeline - How to specify auto retry on failure builds

In Jenkins CI, there's a plugin to "Retry build after failure", where we can specify number of times we want the build to auto trigger when job fails.

Does something similar in Azure Devops, where the pipeline will auto trigger when build fails?



Solution 1:[1]

It seems possible since November 2021 to retry a failing task, at least in YAML pipelines.

Docs: Automatic retries for a task

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

While this is not retrying the whole pipeline, it might be enough for many use cases.

Solution 2:[2]

At present, In the Azure Devops, we do not have such auto retry option.

You can view the user voice ticket here Rerun failed build task/step:

But there is a rest api you can specify ?retry=true:

PATCH https://dev.azure.com/{organizationName}/{ProjectID}/_apis/build/builds/{BuildID}?retry=true

Which will help re-run the failed job.

I created a PowerShell demo:

$connectionToken="$(PAT)"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
  
$response = Invoke-RestMethod 
    -Uri 'https://dev.azure.com/MyCustomOrganization/MyTestProject/_apis/build/builds/7364?retry=true&api-version=6.0'
    -ContentType "application/json-patch+json"
    -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
    -Method PATCH

Hope this helps

Solution 3:[3]

For classic release pipelines there is a retry option nowadays:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paweł Bulwan
Solution 2 KyleMit
Solution 3 Julian