skip to Main Content

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://learn.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


  1. 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: ...
    
    Login or Signup to reply.
  2. It’s also located under "Control Options" when the "Command Line" task is added:
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search