azure-devops-rest-api - 使用 Azure DevOps REST API 更新发布定义因旧副本而失败
问题描述
我正在尝试利用 DevOps API 来更新新的发布定义。最终,我将在发布定义中添加一个新环境,但现在我只是想让更新 (PUT) 方法工作。
我已经参考了这篇文章的信息。
下面的代码获取一个现有的发布定义(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":"您正在使用发布管道的旧副本。刷新您的副本并重试。","typeName": "Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000})
是否需要进行其他更改才能成功进行更新?
解决方案
删除$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
.
推荐阅读
- java - 将带偏移量的时间转换为 UTC 并返回 localdatetime
- azure-pipelines - 如何修复端点管理员意外失去权限的端点?
- c++ - 无法从基于 libstdc++ 策略的数据结构中删除
- angular - Angular 2 稍后将表单控件转换为表单组
- http - 如何实现 HTTP 中继/隧道来访问 Web 应用程序?
- forms - 仍然无法使用 Symfony 验证收集表单
- angular - 为什么设置 cookie 不能与来自外部 API 的角度和服务工作者一起使用
- python-3.x - 如何检查字符串是否仅包含字母或仅包含数字?
- api - 如何使用 __groovy 评估 java 函数并将其分配为 Http Request 的一部分
- jmeter - 在 JMeter 5.2 中使用 CEGID 应用程序记录