You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Pipelines中任务执行失败时如何实现分支跳转逻辑?

Azure Pipelines 任务分支逻辑实现

你可以通过任务内置的条件判断属性直接实现需求,两种适用场景的配置如下:

场景1:npm1之后直接接npm2a、npm2b,无其他中间任务

直接使用流水线内置的状态判断函数即可:

# npm1任务
- task: Npm@1
  inputs:
    command: 'custom'
    customCommand: 'run 替换为你的npm1对应命令'
  displayName: '执行npm1任务'

# npm2a任务,仅npm1执行成功时运行
- task: Npm@1
  inputs:
    command: 'custom'
    customCommand: 'run 替换为你的npm2a对应命令'
  displayName: '执行npm2a任务'
  condition: succeeded()

# npm2b任务,仅npm1执行失败时运行
- task: Npm@1
  inputs:
    command: 'custom'
    customCommand: 'run 替换为你的npm2b对应命令'
  displayName: '执行npm2b任务'
  condition: failed()

场景2:npm1和npm2a/2b之间存在其他任务,不受其他任务状态影响

需要显式指定仅判断npm1的执行结果:

# npm1任务
- task: Npm@1
  name: npm1
  inputs:
    command: 'custom'
    customCommand: 'run 替换为你的npm1对应命令'
  displayName: '执行npm1任务'
  continueOnError: true # 避免npm1失败后直接终止流水线

# npm2a任务,仅npm1执行成功时运行
- task: Npm@1
  inputs:
    command: 'custom'
    customCommand: 'run 替换为你的npm2a对应命令'
  displayName: '执行npm2a任务'
  condition: eq(dependencies.npm1.result, 'Succeeded')

# npm2b任务,仅npm1执行失败时运行
- task: Npm@1
  inputs:
    command: 'custom'
    customCommand: 'run 替换为你的npm2b对应命令'
  displayName: '执行npm2b任务'
  condition: eq(dependencies.npm1.result, 'Failed')

内容的提问来源于stack exchange,提问作者DexterBoyGenius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 00:36:07