Friday, December 10, 2021

Task Retries in Azure DevOps Pipelines

Automated processes failing from the intermittent issues (due to connectivity failures etc.) is one of the main challenges you might face while automating build and releases using CI/CD tools. Azure DevOps has introduced new task retry feature as a solution to intermittent failures. You can retry only the failed task multiple times without requeue entire pipeline. This blog is explaining how to use retry in Azure DevOps pipelines.

Following is a PowerShell task in a pipeline which is generating random number and mark task as success if the random number is even, otherwise failing the task with an exception. we have to setup number of retried to enable the feature of retrying on a task failure.

taskPowerShell@2
  inputs:
    targetType'inline'
    script: |
      $val = Get-Random -Maximum 100
      $val | % {if($_ % 2 -eq 0 ) {"$_ is even"} else {throw "Error trying to do a task"}} 
  retryCountOnTaskFailure2     

 Following Azure DevOps log shows how retry works when random number is an odd number.





No comments:

Post a Comment