如何使用 Azure CLI 在 Azure devops 中获取发布管道的变量列表

How to get the list of variable of release pipelines in Azure devops using Azure CLI

我正在使用 Azure CLI,我想获取发布管道中使用的变量列表。 目前我能够使用命令获取构建管道中使用的变量列表 az 管道变量列表

请告诉我如何使用 CLI 获取发布管道中使用的变量列表 "through console I don't want as it is difficult to copy and paste all variable used in release pipeline"

How to get the list of variable of release pipelines in Azure devops using Azure CLI

Azure Devops CLI 中没有可用的命令来列出发布管道的变量,您必须使用 az devops invoke + rest api 来获取您想要的长响应变量。

要获取释放变量,我们可以使用此 rest api,让我将其转换为 az devops invoke 命令:

az devops invoke --org https://dev.azure.com/MyOrgName/ --area release --resource definitions --http-method Get --route-parameters project=MyProjectName definitionId=ReleaseDefinitionID --api-version 5.1 -o json

更多详情:

1.You 应将 MyOrgName、MyProjectName 和 ReleaseDefinitionID 替换为您这边的值。当我们在 Web 门户中编辑发布管道时,ReleaseDefinitionID 很容易找到:

2.Since 发布管道中的变量可以限定在一个阶段或整个管道中。假设我在 stage1 中有 VarA:Test1,在 stage2 中有 VarB:Test2,在整个发布管道中有 VarC:Test3。响应看起来像这样的结构:

"variables": {
        "VarC": {
            "value": "Test3"
        }
    },
    "variableGroups": [],
    "environments": [
        {
            "id": 1,
            "name": "Stage 1",
            ...
            "variables": {"VarA" xxx},

            "id": 2,
            "name": "Stage 2",
            ...
            "variables": {"VarB" xxx}...

变数有高低之分,请慎重。希望对你有帮助。

更新1:

要使用 az devops 命令,没有此扩展的人需要使用类似 az extension add --name azure-devops.

的方式添加 devops 扩展

使用以下命令可以实现与@Lance Li-MSFT 描述的几乎相同的输出

az pipelines release definition show --project YourProjectName --id YourReleaseDefinitionId

阶段特定变量在 environments 节点中,而全局变量在节点 variables 中。