azure-devopsazure-pipelinesazure-devops-rest-apiazure-deploymentazure-devops-server-2019

what is the way to get the variable group id of AzureDevops using CLI command


We are using AzureDevops server and automated our pipeline variable group and variables creation using a pre-build task which will run bash script below and will gerate the variabel and Variable group together

Since its a sensitive information, we would need to hide this variables value, so came across the article about the secret vraiable.. But its identified that we cant use the same az command which we were using the VG and variables together for the secret variable creation and would need to call the existing created VG by its group id and need to pass the secret value as a second step.

So here the problem i am facing is

In my curret bash script, we are using the below commands to create variable group and variable together.

az pipelines variable-group create --project=myproject --name $variable_group_name --authorize true --variables mynKey=$my_key

So if I want to split this to commands, not sure how I can obtain the group id for the created variable group.

az pipelines variable-group create  --project=$projectname --name $variable_group_name --authorize true

az pipelines variable-group variable create --group-id <?????> --name myKey --project=$projectname --secret  true --value $my_key

Solution

  • In the Response of the Azure DevOps CLI(az pipelines variable-group create), it can contain the created Variable Group ID.

    enter image description here

    You can directly get the ID in the CLI response.

    Here is an example:

    ID=$(az pipelines variable-group create --org "https://dev.azure.com/xx/" --project "azure" --name "xx" --authorize true --variables "key=value" --query 'id' -o  json)
    
    
    echo  $ID
    

    enter image description here

    You can also set the Groupid as Pipeline variable with logging command.

    echo "##vso[task.setvariable variable=GroupID]$ID"
    

    Here is the doc about get value in CLI response.