Azure devops 是否可以在项目之间克隆变量组?

Azure devops 是否可以在项目之间克隆变量组?,azure-devops,azure-pipelines,Azure Devops,Azure Pipelines,我知道您可以克隆变量组,但这在项目中是有限的。 是否可以将其克隆到其他项目?azure devops UI portal中没有克隆项目之间变量组的功能 但是,您可以通过使用来实现这一点 首先,需要调用get variable group rest api来获取变量内容 GEThttps://dev.azure.com/{organization}/{project}/_api/distributedtask/variablegroups/{groupId}?api版本=5.1-preview.1

我知道您可以克隆变量组,但这在项目中是有限的。
是否可以将其克隆到其他项目?

azure devops UI portal中没有克隆项目之间变量组的功能

但是,您可以通过使用来实现这一点

首先,需要调用get variable group rest api来获取变量内容

GEThttps://dev.azure.com/{organization}/{project}/_api/distributedtask/variablegroups/{groupId}?api版本=5.1-preview.1

然后使用addvariablegroupsrestapi将一个新变量组添加到另一个项目中,该项目包含来自getrestapi的变量内容

POSThttps://dev.azure.com/{organization}/{project}/_api/distributedtask/variablegroups?api版本=5.1-preview.1

请参见下面的powershell脚本示例:

#get the variable group in projectA
$url = "https://dev.azure.com/{organization}/{projectA}/_apis/distributedtask/variablegroups/{groupId}?api-version=5.1-preview.1"

$PAT= "Personal access token"

$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))

$result=Invoke-RestMethod -Uri $url -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo1)} -Method get -ContentType "application/json" 

#Call add variable group rest api to add variable group in ProjectB
$updateurl = "https://dev.azure.com/{organization}/{projectB}/_apis/distributedtask/variablegroups?api-version=5.1-preview.1"

$body = $result | ConvertTo-Json -Depth 10

Invoke-RestMethod -Uri $updateurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo1} -ContentType "application/json"  -Method post -Body $body

您还可以使用azure devops命令行
az pipelines变量组创建
。有关更多信息,请参阅。

azure devops UI portal中没有克隆项目之间变量组的功能

但是,您可以通过使用来实现这一点

首先,需要调用get variable group rest api来获取变量内容

GEThttps://dev.azure.com/{organization}/{project}/_api/distributedtask/variablegroups/{groupId}?api版本=5.1-preview.1

然后使用addvariablegroupsrestapi将一个新变量组添加到另一个项目中,该项目包含来自getrestapi的变量内容

POSThttps://dev.azure.com/{organization}/{project}/_api/distributedtask/variablegroups?api版本=5.1-preview.1

请参见下面的powershell脚本示例:

#get the variable group in projectA
$url = "https://dev.azure.com/{organization}/{projectA}/_apis/distributedtask/variablegroups/{groupId}?api-version=5.1-preview.1"

$PAT= "Personal access token"

$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))

$result=Invoke-RestMethod -Uri $url -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo1)} -Method get -ContentType "application/json" 

#Call add variable group rest api to add variable group in ProjectB
$updateurl = "https://dev.azure.com/{organization}/{projectB}/_apis/distributedtask/variablegroups?api-version=5.1-preview.1"

$body = $result | ConvertTo-Json -Depth 10

Invoke-RestMethod -Uri $updateurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo1} -ContentType "application/json"  -Method post -Body $body
您还可以使用azure devops命令行
az pipelines变量组创建
。有关更多信息,请参阅