我正在尝试利用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:错误的请求({“ $ 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
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句