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
相关产品推荐
相关产品推荐

