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

Azure Pipeline日期参数默认值设置:自动填充当前日期或年份+2

Azure Pipeline 参数默认值设置当前日期及年份计算方案

Azure Pipeline的参数默认值是在管道触发前的预处理阶段解析的,因此不能直接使用运行时的$(...)变量,需要使用**模板表达式($[...]包裹)**来实现日期计算和格式化。

1. 设置当前日期为参数默认值

使用预处理阶段的pipeline.startTime变量(代表管道触发的时间),配合formatDateTime函数格式化日期,即可将当前日期设为StartDate的默认值:

parameters:
  - name: StartDate
    displayName: StartDate
    type: string
    default: $[formatDateTime(pipeline.startTime, 'dd/MM/yyyy')]

该表达式会在管道触发前计算完成,自动填充格式化后的当前日期作为参数默认值,用户仍可手动修改。

2. 实现年份加2的日期计算

如果需要默认值为当前日期加2年,可使用addYears函数对pipeline.startTime进行年份偏移,再格式化:

parameters:
  - name: StartDate
    displayName: StartDate
    type: string
    default: $[formatDateTime(addYears(pipeline.startTime, 2), 'dd/MM/yyyy')]

此方案同样在预处理阶段完成计算,生成的日期字符串可直接用于后续ARM模板输入。

关键说明

  • 模板表达式($[...])是Azure Pipeline预处理阶段支持的语法,仅能使用该阶段可用的变量和函数(如pipeline.startTime、formatDateTime、addYears等)。
  • 运行时变量($(...))只能在管道执行阶段使用,无法用于参数默认值的初始化。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 05:25:42