【问题标题】:Change variable group value of Azure Pipeline更改 Azure Pipeline 的变量组值
【发布时间】:2020-11-16 07:34:36
【问题描述】:

我在 Azure Pipeline 中有一个变量组(见附件),

我想通过下面提到的条件将 isPOS 的值更改为 False,

$angular = (Get-Content "$(system.defaultworkingdirectory)/amaze-commerce/angular.json" -Raw) | ConvertFrom-Json
   
   if ($angular.defaultProject -ne "ecomm-ac-ecomm"){
    // Please add your code here
   }

您能否指导我更改变量组值,我想在发布管道中使用相同的值。

【问题讨论】:

  • 您好,没有最新消息。这个问题有更新吗?请检查 Assael Azran 的回答是否对您有帮助。

标签: azure azure-devops azure-pipelines


【解决方案1】:

要更改变量组的值,请使用Azure DevOps Api

如何更新变量组的示例:

Variablegroups - 获取变量组 - 按 {groupName} 过滤

$pat ="<your-tfs-security-token>"
$read = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$pat"))

$variableGroupName = "Check for angular.json"

$variableGroupId = ((Invoke-RestMethod -Method Get -Headers @{'Authorization' = "Basic $read" } -Uri "https://{instance}/{collection}/{project}/_apis/distributedtask/variablegroups?groupName=${variableGroupName}").Value).id

变量组 - 更新

    $body =@"
    {
      "variables": {
        "isPOS": {
          "value": $false
        }
      },
      "type": "Vsts",
      "name": "${variableGroupName}",
      "description": "Updated variable group"
    }
"@

    $response= (Invoke-RestMethod -Uri "https://{instance}/{collection}/{project}/_apis/distributedtask/variablegroups/${variableGroupId}?api-version=5.0-preview.1"  -Method Put  -Headers @{'Authorization' = "Basic $read" }  -ContentType "application/json" -Body $body)

【讨论】:

猜你喜欢
  • 2020-11-13
  • 1970-01-01
  • 2022-01-08
  • 1970-01-01
  • 2023-04-04
  • 2021-07-29
  • 1970-01-01
  • 1970-01-01
  • 2021-02-03
相关资源
最近更新 更多