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

ADO管道:如何为Cron触发运行设置指定参数并区分运行类型?

解决方案

有两种可行的方式实现你的需求,分别是通过预定义变量判断触发类型和在Cron调度中直接指定参数值,具体如下:

方法一:利用预定义变量判断调度触发

Azure DevOps提供了预定义变量Build.Reason,当管道由调度触发时,该变量的值为Schedule。你可以修改步骤的条件,让调度触发时强制执行打标操作,手动运行时则遵循参数设置:

schedules:
  - cron: 0 5 * * 0-5
    displayName: At 5:00 UTC on all days except Saturday
    branches:
      include:
      - my_branch
    always: true

parameters:
  - name: TagDevelopmentReady
    type: boolean
    values: [true, false]
    default: false

steps:
  - task: AddTag@0
    displayName: Tag Build with 'DevelopmentReady'
    condition: or(eq(variables['Build.Reason'], 'Schedule'), eq(${{ parameters.TagDevelopmentReady }}, true))
    inputs:
      tags: 'DevelopmentReady'

如果要读取调度触发时的Schedule标签,也可以用Build.Tags变量结合contains函数判断,条件可修改为:

condition: or(contains(variables['Build.Tags'], 'Schedule'), eq(${{ parameters.TagDevelopmentReady }}, true))

方法二:在Cron调度中直接覆盖参数值

Azure DevOps支持在调度配置中直接指定参数值,这样调度触发时会强制使用你设置的参数值,手动运行时仍保留原参数的默认值和可修改性:

schedules:
  - cron: 0 5 * * 0-5
    displayName: At 5:00 UTC on all days except Saturday
    branches:
      include:
      - my_branch
    always: true
    parameters:
      TagDevelopmentReady: true # 调度触发时强制设为true

parameters:
  - name: TagDevelopmentReady
    type: boolean
    values: [true, false]
    default: false

steps:
  - task: AddTag@0
    displayName: Tag Build with 'DevelopmentReady'
    condition: eq(${{ parameters.TagDevelopmentReady }}, true)
    inputs:
      tags: 'DevelopmentReady'

这种方式更直接,无需额外条件判断,调度触发时参数会自动被覆盖为true,完全匹配你的需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 09:15:09