Azure多阶段管道:有条件地跳过一个阶段,但不跳过下一个阶段

 收藏

我有一个Azure多阶段CI / CD管道。它具有测试和UAT部署的阶段。

如果测试成功或被跳过,我希望UAT发行版运行,但是如果失败,则不希望这样做。

I can't. Whatever I try, if Test is skipped, UAT is also skipped. Unless I use always(), but then UAT will run even if Test fails.

  ...
  - stage: Test
    condition: and(succeeded(), ne(variables['build.sourceBranchName'], 'DoUAT')) # Skip for UAT deployment tests
    ...

  - stage: UAT
    condition: and(succeeded(), in(variables['build.sourceBranchName'], 'master', 'DoUAT')) # Only deploy off master branch and branch to test UAT deploys.
    ...

如何跳过一个阶段,而不跳过下一个阶段?

What I get vs what I want

回复
  • sunde 回复

    I think it's because the stage doesn't run that it doesn't get a status (eg succeeded, failed, canceled etc.). There is no status function for skipped.

    With that, I think you will need to add a dependency on the stage before Test so that this evaluation can be made. Let's say that stage is called Build.

    我认为这种情况应该有效:(换行符仅供阅读)

    # run the stage if build is successful 
    # and test succeeded or skipped 
    # AND the branch is correct
    and(
      and(succeeded('Build'), not(failed('Test'))), 
      in(variables['build.sourceBranchName'], 'master', 'DoUAT')
    )
    
    失败了         工作:         不带参数的情况下,仅当依赖关系图中的任何先前作业失败时,才将其评估为True。   将作业名称作为参数,仅当这些作业中的任何一个失败时,才求值为True。

    Because of this documentation, I think it's necessary to add the Test parameter to target that stage specifically. However, I'm not sure if this necessitates that the Test name be added to the dependencies section of the UAT stage.