2
votes

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"

2
There's no api/command available can return the release variables, the closest method is to use definitions-related api/command to get long response, and filter the response to get the info you want. But this is about how to filter the json response, which is another topic related to json/Powershell or what... So i don't talk it here.LoLance
Yes I tried have added comment you can go through the comment now the issue left for me is only how to get the variable out of the json anyways thanks for the response you can close that questionSahil Kandroo

2 Answers

4
votes

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:

enter image description here

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
votes

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.