首页 > 解决方案 > Azure Devops-如何验证组织中是否存在团队(Azure CLI 或 Azure Bash)

问题描述

AzureOrganization="https://dev.azure.com/ExampleOrganization"
AzureProject="ExampleProject"
az devops configure -d organization= $AzureOrganization project=$AzureProject

read-r-p "Enter name of iteration" iteration
echo @ iterationname 

如果组织项目中存在@迭代,则完美如果不存在@迭代,则打印出该迭代在项目中不存在

read-r-p "Enter name of team in the organization that you want to link in the iteration " team
echo @ team

如果组织项目中存在@team,那么如果@team不存在则完美,打印出这个团队在项目中不存在

那么我如何知道 Azure Devops 组织中是否已经存在团队或迭代?

标签: bashazureazure-devopsazureshell

解决方案


要确定是否存在团队,您可以使用

team=`az devops team show --team myTeamName 2>/dev/null`

if [ "$team" = "" ]; then
  echo "Team does not exist"
else
  echo "Team exists"
fi

如果团队存在,$team将在其中包含 JSON,否则不包含。

要确定是否存在迭代,您可以使用

iteration=`az boards iteration project list --path "\\ProjectRoot\\Path\\To\\Your\\Iteration" 2>/dev/null`

if [ "$iteration" = "" ]; then
  echo "Iteration does not exist"
else
  echo "Iteration exists"
fi

查看您的项目迭代结构,了解如何构建对路径的查询。我的迭代树有 4 层深。你的可能不是。如果迭代存在,$iteration将在其中包含 JSON,否则不存在。

2>/dev/null迭代或团队不存在时,抑制来自 CLI 的 stderr 输出。--only-show-errors不压制这一点。

if语句可能因外壳而异(我使用)zsh,因此如果这不起作用,您可能需要查看您正在使用的外壳的文档。


推荐阅读