Search code examples
azureyamlazure-pipelinespipeline

Yaml multi stage run using dependson and conditions


I have a need to run the "Secure" stage if one of the previous stages of INT was sucessfully passed. I tried with dependson and conditions but I can't find the solution.

enter image description here


Solution

  • I have a need to run the "Secure" stage if one of the previous stages of INT was sucessfully passed.

    I am afraid there is no such out of YAML syntax to achieve this at this moment.

    Since we need to set multiple depend on for the stage Secure:

    - stage: Deploy
      dependsOn:
        - INT_API
        - INT_FuncIntergration
        - INT_Web
      condition: or(succeeded('INT_API'), succeeded('INT_FuncIntergration'), succeeded('INT_Web'))
    

    Restriction:

    This method can only be used the previous stage has a success, then this stage will be executed, but the current stage needs to be executed after all the previous stages have been executed. If you need to execute the current stage as long as one of the previous stages is successful, this method is still not enough.

    That is because there is no "OR" syntax for the depend on. And we could not add the condition for the depend on, like:

     - stage: Deploy
       ${{ if eq(result.INT_API, successed) }}:
        dependsOn:
          - INT_API
          - INT_FuncIntergration
          - INT_Web
        condition: or(succeeded('INT_API'), succeeded('INT_FuncIntergration'), succeeded('INT_Web'))
    

    Because the condition is parsed when YAML is compiled, but at this time the running result of the previous stage has not yet come out.

    You could submit this request condition "OR" to our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions. Thank you for helping us build a better Azure DevOps.

    Workaround:

    The main idea of the solution is: You could try to set depend on for the stage Secure with [], then add a Inline powershell task before other tasks. This task will call the REST API Definitions - Get to monitor whether all the stages in the current release pipeline have inprocess and queue states. If so, wait for 30 seconds, and then loop again until all other stages in the current release pipeline have no inprocess and queue states. Then next execute other tasks will be executed.

    You could check my previous ticket for detailed info: