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

Azure DevOps如何通过Azure CLI/Bash校验组织内团队、迭代是否存在

Azure DevOps 迭代/团队存在性判断Bash脚本实现

前置依赖

  • 已安装Azure CLI及Azure DevOps扩展:未安装可执行 az extension add --name azure-devops
  • 已通过 az login 完成登录,且账号对目标项目有读取权限

完整可运行脚本

# 基础配置
AzureOrganization="https://dev.azure.com/ExampleOrganization"
AzureProject="ExampleProject"
# 修正原参数多余空格问题
az devops configure -d organization=$AzureOrganization project=$AzureProject

# 读取迭代名称
read -r -p "Enter name of iteration: " iteration
# 判断迭代是否存在
iteration_exists=$(az boards iteration project list --query "length([?name == '$iteration'])")
if [ "$iteration_exists" -gt 0 ]; then
    echo "迭代 $iteration 存在于当前项目中"
else
    echo "该迭代不存在于当前项目中"
    exit 1
fi

# 读取团队名称
read -r -p "Enter name of team in the organization that you want to link in the iteration: " team
# 判断团队是否存在
team_exists=$(az devops team list --query "length([?name == '$team'])")
if [ "$team_exists" -gt 0 ]; then
    echo "团队 $team 存在于当前项目中"
else
    echo "该团队不存在于当前项目中"
    exit 1
fi

核心逻辑说明

  • 迭代判断调用 az boards iteration project list 获取项目下所有迭代,通过JMESPath查询匹配名称的迭代数量,数量大于0则表示存在
  • 团队判断调用 az devops team list 获取项目下所有团队,同样通过匹配名称的返回数量判断存在性
  • 若需要匹配子层级迭代,可修改查询条件匹配path字段而非name字段

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 13:06:05