Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 631
Vowneee Avatar asked Oct 28 '25 06:10

Vowneee


2 Answers

$group_id = $(az pipelines variable-group list -p $(System.TeamProject) --group-name "variable_group_name" --query '[0].id' -o json)

This fetches the variable group id into the $group_id variable

If the variable group does not exists then the above will simply returns empty result

like image 72
Guru Prasad Avatar answered Oct 31 '25 09:10

Guru Prasad


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.

like image 37
Kevin Lu-MSFT Avatar answered Oct 31 '25 10:10

Kevin Lu-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!