【发布时间】: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