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

如何通过Azure DevOps CLI将新建工作项添加至当前Sprint?

将新建工作项添加至当前运行Sprint的方法

可行,以下是具体操作方法:

核心原理

Azure DevOps中Sprint对应迭代路径(Iteration Path),只需给工作项指定当前Sprint的迭代路径,就能将其加入该Sprint。

步骤1:获取当前运行Sprint的迭代路径

先通过CLI命令查询当前处于活跃状态的Sprint完整路径:

az boards iteration list --project <你的项目名称> --depth 1 --query "[?attributes.startDate <= now() && attributes.finishDate >= now()].path" -o tsv

返回结果格式类似项目名称\迭代\Sprint名称,直接复制即可使用。

方法一:创建工作项时直接关联Sprint

修改你原有的创建命令,添加IterationPath字段参数(注意拆分原命令中合并的字段,避免格式错误):

az boards work-item create \
  --title Test \
  --type Task \
  --project <你的项目名称> \
  --assigned-to <用户邮箱> \
  --fields "Description=PR is open, please test the new exe version and approve" \
           "Priority=2" \
           "IterationPath=<步骤1获取的迭代路径>"

方法二:已创建工作项事后添加至Sprint

如果工作项已经创建完成,可通过工作项ID更新其迭代路径:

  1. 先获取目标工作项的ID(可通过az boards work-item list查询,或从Azure DevOps界面查看)
  2. 执行更新命令:
az boards work-item update \
  --id <工作项ID> \
  --project <你的项目名称> \
  --fields "IterationPath=<步骤1获取的迭代路径>"

流水线中自动化实现

在Azure DevOps流水线里,可以把获取迭代路径的步骤封装为变量,自动完成关联:

# 获取当前Sprint路径并存为变量
current_sprint=$(az boards iteration list --project $(System.TeamProject) --depth 1 --query "[?attributes.startDate <= now() && attributes.finishDate >= now()].path" -o tsv)

# 创建工作项并自动关联当前Sprint
az boards work-item create \
  --title "Test" \
  --type Task \
  --project $(System.TeamProject) \
  --assigned-to "<用户邮箱>" \
  --fields "Description=PR is open, please test the new exe version and approve" \
           "Priority=2" \
           "IterationPath=$current_sprint"

注意:确保执行CLI命令的账号拥有创建/修改工作项以及访问迭代路径的权限。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 04:33:37