Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export multiple Azure DevOps Variable Groups?

We have multiple variable groups in our project and I am trying to find ways how I can export them to my local desktop.

So far I have this az script that exports a variable group but I can only do one at a time. I have several variables and I am trying to do all of them at once. Could someone please help on how I can export multiple variables and use the same name of that variable on Azure DevOps to match it when it's saved on the desktop?

az pipelines variable-group show --group-id "id number" --org "https://dev.azure.com/Organization" -p "Project" --output json > test.json

Also when I use the script, the value for secret is showing as "null" instead of "false"? Any reason why it's doing that?

like image 216
albbla91 Avatar asked Apr 07 '26 00:04

albbla91


2 Answers

You can use below command to export multiple variable groups at a time. See: az pipelines variable-group for details.

az pipelines variable-group list --org "https://dev.azure.com/Organization" --project "Project" --output json>test.json

In addition, this secret variable is encrypted in variable group by reference to this doc: Add & use variable groups, thus we can only get "null" from return result, which is by design. If you want to use secret variables in Azure Pipelines, please see: Set secret variables for guidance.

like image 178
Edward Han-MSFT Avatar answered Apr 08 '26 15:04

Edward Han-MSFT


To download variable groups in different json file, I've created a script that collects all variable groups, gets their names, and creates folder and files for each variable group. It will create a subfolder VariableGroups in current folder.

$ProjectName = "projectName"
$Organization = "https://dev.azure.com/organizationName" 
# Get variable-groups list
$vars = az pipelines variable-group list --organization $Organization --project $ProjectName

# Get variable-groups names list
$v = $vars | ConvertFrom-Json -AsHashtable
$variable_group_names = $v.name

# Go though every variable-group
foreach ($variable_group_name in $variable_group_names) {
    $group = az pipelines variable-group list --organization $Organization --project $ProjectName --group-name $variable_group_name
    
    # Get every variable-group Id
    $g = $group | ConvertFrom-Json -AsHashtable
    $groupId = $g.id
   
    
    # Check if VariableGroups folder exist, if not - create it
    if (!(Test-Path .\VariableGroups)){
        New-Item -itemType Directory -Path .\VariableGroups
    } 
    
    # Get every variable-group content and place it in corresponding folder
    az pipelines variable-group show --organization $Organization --project $ProjectName --id $groupId  --output json>.\VariableGroups\$variable_group_name.json
    Write-Host created .\VariableGroups\$variable_group_name.json
}
like image 44
Maks Kost Avatar answered Apr 08 '26 15:04

Maks Kost



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!