使用Azure DevOps REST API的更新版本定义因旧副本而失败

问题描述

我正在尝试利用DevOps API更新新的发行版定义。最终,我将在发布定义中添加一个新环境,但现在我只是想使更新(PUT)方法起作用。
我已引用帖子this post以获得信息。

下面的代码获取现有的发行版定义(id = 15),修改版本,删除lastRelease属性,然后更改说明以更改内容

function getreleasedeFinitionrequest($deFinitionid,$org,$project)
{
 $requestpath = "/_apis/release/deFinitions/" + $deFinitionid + "?api-version=6.0-preview.4"
 $tokeninfo = az account get-access-token | convertfrom-json
 $token = $tokeninfo.accesstoken
 $uribase = "https://vsrm.dev.azure.com/" + $org + "/" + $project
 $uri = $uribase+$requestpath
 $authheader = "Authorization=Bearer " + $token
 $result = az rest --uri $uri --headers $authheader | convertfrom-json
 return $result
}

function putreleasedeFinitionrequest($bodyfile,$project)
{
 $requestpath = "/_apis/release/deFinitions?api-version=6.0-preview.4"
 $tokeninfo = az account get-access-token | convertfrom-json
 $token = $tokeninfo.accesstoken
 $uribase = "https://vsrm.dev.azure.com/" + $org + "/" + $project
 $uri = $uribase+$requestpath
 $authheader = "Authorization=Bearer " + $token
 $result = az rest --method put --uri $uri --headers "Content-Type=application/json" $authheader --body @$bodyfile | convertfrom-json
 return $result
}

$deFinition15 = getreleasedeFinitionrequest "15" {org} {project} | select -Last 1

#bump the revision and delete the lastRelease property
$rev = [int] $deFinition15.revision
$rev++
$deFinition15.revision = $rev
$deFinition15.PSObject.properties.remove('lastRelease')
$deFinition15.description = "make up a change to the description"

$bodyfile = ".\body.json"

$body = $deFinition15 | convertto-json -Depth 100 | Set-Content -Path $bodyfile

#upate release deFinition
$putresult = putreleasedeFinitionrequest $bodyfile {org} {project} | select -Last 1

az rest --method抛出错误代码,抱怨该发行版是旧副本。我从相同版本的API中提取了请求,并如上所述进行了更改。因此,我认为这个新修订版是管道的全新版本。

az:错误的请求({“ $ id”:“ 1”,“ innerException”:null,“ message”:“您是 使用发布管道的旧副本。刷新您的副本并尝试 再次。“,” typeName“:” Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data“,” typeKey“:” InvalidRequestException“,” errorCode“:0,” eventId“:3000})

成功进行更新是否需要其他更改?

解决方法

删除Trie = lambda: collections.defaultdict(Trie) root = Trie() cur = root for c in 'hello': cur = cur[c] ,我们不要,也不应该手动更改$rev++的值。

注意:如果您仔细阅读了该帖子,将会看到revision。因此,我们实际上不需要更改它,错误I set the revision number to be the number it is currently on and it works now总是由You are using an old copy of the release pipeline的变化引起的。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...