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

廉价感情. 提交于 2020-06-29 04:53:08

问题


I am Using Azure CLI, What I want to get the list of variable used in release pipeline . Current I am able to get the list of variable used in build pipeline using command az pipelines variable List

Please let know how can I get the list of variables used in release pipeline using CLI "through console I don't want as it is difficult to copy and paste all variable used in release pipeline"


回答1:


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

There's no command available in Azure Devops CLI to list the variables of release pipeline, you have to use az devops invoke + rest api to get the variables you want in long response.

To get release variables we can use this rest api, let me convert it into az devops invoke command :

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

More details:

1.You should replace the MyOrgName, MyProjectName and ReleaseDefinitionID with the values on your side. And the ReleaseDefinitionID is something easy to find when we edit a release pipeline in web portal:

2.Since variables in release pipeline can be scoped in one stage or whole pipeline. Assuming I have VarA:Test1 in stage1, VarB:Test2 in stage2, and VarC:Test3 in whole release pipeline. The response would look like this structure:

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

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

The variables have their different levels, please be careful with them. Hope it helps.

Update1:

To use az devops command, someone who doesn't have this extension needs to add the devops extension using something like az extension add --name azure-devops.




回答2:


Almost the same output as described by @Lance Li-MSFT can be achieved by using the following command

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

The stage-specific variables are in the environments node whereas the global variables are in the node variables.



来源:https://stackoverflow.com/questions/61325671/how-to-get-the-list-of-variable-of-release-pipelines-in-azure-devops-using-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!