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

基于Azure CLI/Bash的Azure Devops团队与迭代存在性校验实现

基于Azure CLI的Azure DevOps资源校验Bash函数

前置基础配置

以下配置需要提前替换为你实际的Azure DevOps组织、项目地址,执行后会设置CLI默认上下文,避免后续命令重复传参

  • 使用前请先执行az login登录你的Azure账号,确保账号有对应Azure DevOps项目的读取权限
  • 依赖jq工具处理JSON返回,未安装的可执行apt install jq(Debian/Ubuntu)或brew install jq(macOS)完成安装
AzureOrganization="https://dev.azure.com/ExampleOrganization"
AzureProject="ExampleProject"
az devops configure -d organization=$AzureOrganization project=$AzureProject

函数1:校验指定团队是否存在

传入团队名称作为入参,存在返回true,不存在返回false

check_ado_team_exists() {
  local team_name="$1"
  # 调用Azure CLI查询项目下所有团队,过滤名称匹配的结果
  local match_count=$(az devops team list --query "[?name=='$team_name']" -o json | jq length)
  if [ "$match_count" -gt 0 ]; then
    echo "true"
    return 0
  else
    echo "false"
    return 1
  fi
}

# 使用示例
# check_ado_team_exists "产品研发团队"

函数2:校验指定迭代是否存在

支持传入迭代名称或完整迭代路径作为入参,存在返回true,不存在返回false

check_ado_iteration_exists() {
  local input="$1"
  # 同时匹配迭代名称和迭代路径,命中任意一项即判定存在
  local match_count=$(az boards iteration project list --query "[?name=='$input' || path=='$input']" -o json | jq length)
  if [ "$match_count" -gt 0 ]; then
    echo "true"
    return 0
  else
    echo "false"
    return 1
  fi
}

# 使用示例
# 按迭代名称查询:check_ado_iteration_exists "V2.1版本迭代"
# 按迭代路径查询:check_ado_iteration_exists "ExampleProject\版本迭代\V2.1版本迭代"

内容的提问来源于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:45:03