Vowneee
Vowneee

Reputation: 1481

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

Upvotes: 4

Views: 7194

Answers (4)

goulashsoup
goulashsoup

Reputation: 3116

You can also get the variable from the URL when opening the group on the Azure website: https://dev.azure.com/myorg/project/_library?itemType=VariableGroups&view=VariableGroupView&variableGroupId=175&path=some-var-group

Here the URL parameter variableGroupId gives us the variable id 175.

Upvotes: 2

Guru Prasad
Guru Prasad

Reputation: 639

$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

Upvotes: 3

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35514

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.

Upvotes: 2

Yan Sklyarenko
Yan Sklyarenko

Reputation: 32270

You can use the list command for this. If you provide the full group name of the variable group you've just created, you should get its ID back:

az pipelines variable-group list -p myproject --group-name $variable_group_name

Upvotes: 2

Related Questions