本文介绍了使用 REST API 设置 Azure devops Release 管道变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用下面的 json 主体更新构建管道中的变量

 $body = '{定义": {身份证":25},"参数": "{"var":"value"}"}'

相同的 json 不适用于发布管道.有什么方法可以通过发布管道以相同的方式传递变量

解决方案

我们可以使用 REST API

更新:

但我想在不更新更改定义的情况下实现它

答案是肯定的.您可以使用 发布 - 使用请求正文创建:

{定义ID":ID,环境":[{变量":{测试变量":{值":xxx"},测试变量2":{值":xxx"}},}],}

有关更多信息,请参阅此处的帖子.

希望这会有所帮助.

I am able to update the variable in the build pipeline using the below json body

        $body = '
{
    "definition": {
        "id": 25
    },
    "parameters": "{"var":"value"}"

}
'

The same json is not working with Release pipeline . Is there any way to pass the variable through same way through release pipeline

解决方案

We could use the REST API Definitions - Get to get all the info about this definition in the body, then we could update the body and use the (Definitions - Update) to update the value of the release definition variable from a release pipeline:

PUT https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=5.0

Following is my test inline powershell scripts:

$url = "https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=5.1"

Write-Host "URL: $url"
$pipeline = Invoke-RestMethod -Uri $url -Method Get -Headers @{
    Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)"

# Update an existing variable named TestVar to its new value 2
$pipeline.variables.TestVar.value = "789"

####****************** update the modified object **************************
$json = @($pipeline) | ConvertTo-Json -Depth 99

$updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}

write-host "=========================================================="
Write-host "The value of Varialbe 'TestVar' is updated to" $updatedef.variables.TestVar.value

As test result, the variable TestVar updated to 789:

Update:

The answer is yes. You could use the Releases - Create with request body:

{
  "definitionId": Id,
  "environments": [
    {
      "variables": {
        "TestVar": {
          "value": "xxxx"
        },
        "TestVar2": {
          "value": "xxxx"
        }
      },

    }
   ],
}

For more information refer the post here.

Hope this helps.

这篇关于使用 REST API 设置 Azure devops Release 管道变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 16:28