【问题标题】:Azure Devops-How to verify whether team has exists in an organization (Azure CLI or Azure Bash)Azure Devops-如何验证组织中是否存在团队(Azure CLI 或 Azure Bash)
【发布时间】:2021-11-21 18:56:48
【问题描述】:
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,那么完美 如果@团队不存在,则打印出该团队在项目中不存在

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

【问题讨论】:

    标签: bash azure azure-devops azureshell


    【解决方案1】:

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

    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 的标准错误输出。 --only-show-errors 不会抑制这一点。

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

    【讨论】:

    • 非常感谢——是否有我可以在 If 语句中使用的真/假值,所以如果团队不存在,则打印输出不存在,如果存在,则打印输出存在。我需要在 if 语句中使用 true false 之类的东西
    • 检查我的答案的更新。
    • 表示路径参数应该是绝对路径。你有没有办法通过查询迭代名称来获取路径?非常感谢
    • 为此,您可能需要在没有--path 参数的情况下调用az boards iteration project list,并使用适当的--depth 参数设置(为此查看迭代树的最大深度)。从那里,您将扫描特定迭代名称的输出。
    • 非常感谢...我对这些东西很陌生。我什至不知道如何扫描输出。例如,你得到 az board iteration project list --depth 3。然后,我如何找到 childIteration 是否存在。示例子迭代--ABC。我如何知道 json 文件中存在 ABC 以及我可以通过查询 json 获取 ABC.path 吗?我想问一个新问题。但是因为我的问题被否决了。我不能这么问,这让我在这里发表评论。
    猜你喜欢
    • 1970-01-01
    • 2020-07-10
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 2021-05-05
    相关资源
    最近更新 更多