Azure Pipelines Automatic retries for a task

Viewed 197

This is part of my Yml file I need to re-call this template if it failed.it should be rerun again. After a few seconds, ideally.I am new to yml files I tried to use retryCountOnTaskFailure but it should be under task but the template calling different hierarchy

https://docs.microsoft.com/en-us/azure/devops/release-notes/2021/sprint-195-update#automatic-retries-for-a-task

- template: ${{variables['System.DefaultWorkingDirectory']}}
    parameters:
      Test: ${{ parameters.isTestRelease }}
      Environment: ${{ parameters.deploymentTarget }}
      Component: '${{ parameters.component }}'
2 Answers

The retryCountOnTaskFailure feature is applied to individual tasks within a pipeline. Templates aren't tasks, they act more like an include that expands the contents of the template into your pipeline.

# pipeline.yml

trigger: none

parameters:

- name: isTestRelease
  type: boolean
  default: false

- name: deploymentTarget
  type: string
  default: DEV
  values:
  - DEV
  - QA
  - UAT
  - PROD

- name: component
  type: string
  default: 'x'

stages:
- template: my-template.yml
  parameters:
    Test: ${{ parameters.isTestRelease }}
    Environment: ${{ parameters.deploymentTarget }}
    Component: ${{ parameters.component }}

And within the template, you'd want to add the retry logic to specific tasks:

# my-template.yml

parameters:
- name: isTestRelease
  type: boolean

- name: component
  type: string


stages:
- stage: Test
  jobs:
  - job: 1
    steps:
    - task: ...
    - task: ...

    - task: ...
      retryCountOnFailure: 2

    - task: ...

It's also located under "Control Options" when the "Command Line" task is added: enter image description here

Related