如果失败,如何在 Azure 管道中执行任务分支?

How to do perform a task branching in azure pipelines in case of failure?

我下面有 3 个任务。 我想要做的是当 npm1 成功时,它将执行 npm2a 并跳过 npm2b。 而当npm1失败时,会跳过npm2a,执行npm2b。

这如何在 Azure 管道中完成? 请不要指向我的教程。

How to do perform a task branching in azure pipelines in case of failure?

您可以在 npm1npm2a 之间添加命令行或内联 PowerShell 任务来调用 Logging Commands

Write-Host "##vso[task.setvariable variable=testvar;]npm2b"

然后我们设置这个任务的条件为Only when a previous task has failed

并设置变量 testvar 为默认值 npm2a

此外,设置任务的条件npm2anpm2b:

and(succeeded(), eq(variables['testvar'], 'npm2a'))

and(failed(), eq(variables['testvar'], 'npm2b'))