【问题标题】:Upate Release Definition using Azure DevOps REST API fails with old copy使用 Azure DevOps REST API 更新发布定义因旧副本而失败
【发布时间】:2020-08-21 13:25:02
【问题描述】:

我正在尝试利用 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, $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 : 错误请求({"$id":"1","innerException":null,"message":"你是 使用发布管道的旧副本。刷新您的副本并尝试 再次。","typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000})

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

【问题讨论】:

  • 你可以调试它并在更改前后粘贴定义15 var吗?

标签: azure-devops-rest-api azure-cli2


【解决方案1】:

删除$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的报错总是revision的改造成的。

【讨论】:

    猜你喜欢
    • 2020-05-23
    • 1970-01-01
    • 2020-08-03
    • 2019-11-13
    • 2020-09-17
    • 2021-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多