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

Upate Release Definition using Azure DevOps REST API fails with old copy

我正在尝试利用 DevOps API 来更新新的发布定义。最终,我将向发布定义添加一个新环境,但现在我只是想让更新 (PUT) 方法起作用。
我参考了 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, $org, $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 put 抛出一个错误代码,抱怨版本是旧副本。我从相同版本的 API 中提取了请求,并如上所述进行了更改。所以我认为这个新修订版是管道的全新版本。

az : Bad Request({"$id":"1","innerException":null,"message":"You are using an old copy of the release pipeline. Refresh your copy and try again.","typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000})

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

删除 $rev++,我们 不会也不应该 手动更改 revision 的值。

注意:如果你仔细阅读post,你会看到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 总是由 revision.

的更改引起的