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

如何配置Azure DevOps CI流水线定时运行并指定Variable Group、任务与Azure订阅

解决方案

方案1:修改现有流水线YAML实现(无额外资源,完全符合单流水线要求)

该方案完全在你现有单条CI流水线内完成修改,不会新增任何业务流水线,也不影响原有手动运行的逻辑:

修改步骤

  1. 新增定时触发配置,直接指定美国中部标准时间的两个触发点
  2. 新增触发源判断逻辑:定时触发时自动按规则赋值参数,手动运行时沿用用户手动选择的参数
  3. 按运行时的参数值引入对应Variable Group

完整修改后YAML示例

trigger:
- none

# 新增定时触发配置
schedules:
- cron: "0 19 * * *"
  displayName: 每日19点自动启动Function
  branches:
    include:
    - main # 替换为你的实际分支
  always: true # 即使代码无变更也触发
  timeZone: "Central Standard Time" # 直接指定美国中部标准时间,无需手动换算UTC
- cron: "0 6 * * *"
  displayName: 每日6点自动停止Function
  branches:
    include:
    - main # 替换为你的实际分支
  always: true
  timeZone: "Central Standard Time"

pool:
  vmImage: 'windows-latest'

parameters:
- name: variableGroup
  displayName: Variable Group
  type: string
  values:
  - 'variable for store A'
  - 'variable for store B'
  - 'variable for store C'
  - 'variable for store D'
  - 'variable for store E'
    
- name: artifactVersion
  displayName: ArtifactVersion (* (latest) or 1.{sprintNumber}.{ReleaseNo})
  type: string
  default: '*'

- name: Function
  displayName: Function
  type: string
  default: 'deploy'
  values:
  - deploy  
  
- name: task
  displayName: ExecuteTask
  type: string
  default: ''
  values:
  - start thefunction
  - stop the function
  
- name: Subscription
  displayName: Subscription
  type: string 
  values:
  - 'sandbox'
  - 'production '

# 新增运行时变量判断逻辑
variables:
  # 定时触发时自动赋值执行任务,手动运行时取用户选择的参数
  - name: finalTask
    ${{ if eq(variables['Build.Reason'], 'Schedule') }}:
      ${{ if eq(format('{0:HH}', pipelineStartTime), '19') }}:
        value: 'start thefunction'
      ${{ if eq(format('{0:HH}', pipelineStartTime), '06') }}:
        value: 'stop the function'
    ${{ else }}:
      value: ${{ parameters.task }}
  # 定时触发时自动赋值指定的变量组,手动运行时取用户选择的参数
  - name: finalVariableGroup
    ${{ if eq(variables['Build.Reason'], 'Schedule') }}:
      value: 'variable for store A' # 替换为你要指定的门店变量组
    ${{ else }}:
      value: ${{ parameters.variableGroup }}
  # 定时触发时自动赋值指定的Azure订阅,手动运行时取用户选择的参数
  - name: finalSubscription
    ${{ if eq(variables['Build.Reason'], 'Schedule') }}:
      value: 'production' # 替换为你要指定的订阅
    ${{ else }}:
      value: ${{ parameters.Subscription }}
  # 引入自动选择的变量组
  - group: ${{ variables.finalVariableGroup }}

# 后续原有任务逻辑中,直接使用 $(finalTask)、$(finalSubscription) 作为入参即可

方案2:通过调用DevOps API实现可视化调度配置

如果你需要类似你期望的界面化配置调度参数,可以使用该方案,所有业务逻辑仍保留在你现有CI流水线中,仅新增轻量调度资源:

  • 你可以使用Azure定时函数、Logic Apps等定时服务,调用Azure DevOps流水线运行API,请求体中传入你需要的Variable Group、执行任务、Azure订阅参数
  • 将定时规则设置为美国中部标准时间每日19点、6点触发即可
  • 该方案无需修改现有业务流水线的YAML配置,调度参数可直接在定时服务的配置界面修改

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.05 03:09:03