如何导出多个 Azure DevOps 变量组?
How to export multiple Azure DevOps Variable Groups?
我们的项目中有多个变量组,我正在尝试寻找将它们导出到本地桌面的方法。
到目前为止,我有这个导出变量组的 az 脚本,但我一次只能执行一个。我有几个变量,我正在尝试一次完成所有变量。有人可以帮助我如何导出多个变量并在 Azure DevOps 上使用该变量的相同名称来匹配保存在桌面上的变量吗?
az pipelines variable-group show --group-id "id number" --org "https://dev.azure.com/Organization" -p "Project" --output json > test.json
另外,当我使用脚本时,secret 的值显示为“null”而不是“false”?它这样做有什么原因吗?
您可以使用以下命令一次导出多个变量组。参见:az pipelines variable-group 了解详情。
az pipelines variable-group list --org "https://dev.azure.com/Organization" --project "Project" --output json>test.json
另外,这个秘密变量是在变量组中加密的,参考这个文档: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作为指导。
为了在不同的 json 文件中下载变量组,我创建了一个脚本来收集所有变量组,获取它们的名称,并为每个变量组创建文件夹和文件。它将在当前文件夹中创建一个子文件夹 VariableGroups。
$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
}
我们的项目中有多个变量组,我正在尝试寻找将它们导出到本地桌面的方法。
到目前为止,我有这个导出变量组的 az 脚本,但我一次只能执行一个。我有几个变量,我正在尝试一次完成所有变量。有人可以帮助我如何导出多个变量并在 Azure DevOps 上使用该变量的相同名称来匹配保存在桌面上的变量吗?
az pipelines variable-group show --group-id "id number" --org "https://dev.azure.com/Organization" -p "Project" --output json > test.json
另外,当我使用脚本时,secret 的值显示为“null”而不是“false”?它这样做有什么原因吗?
您可以使用以下命令一次导出多个变量组。参见:az pipelines variable-group 了解详情。
az pipelines variable-group list --org "https://dev.azure.com/Organization" --project "Project" --output json>test.json
另外,这个秘密变量是在变量组中加密的,参考这个文档: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作为指导。
为了在不同的 json 文件中下载变量组,我创建了一个脚本来收集所有变量组,获取它们的名称,并为每个变量组创建文件夹和文件。它将在当前文件夹中创建一个子文件夹 VariableGroups。
$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
}