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

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

Lance Li-MSFT

删除$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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用REST API获取与Azure Devops中的构建关联的更改

无法使用Azure DevOps API获取最新版本

在Azure DevOps版本定义中下载最新版本的版本工件时找不到最新版本

使用Azure DevOps REST Api如何获取分支的提交哈希?

使用Rest API获取Azure DevOps构建的构建结果

使用Azure DevOps REST API更新许可证级别

如何使用Azure devops Rest Api获取最新标签?

如何使用Azure DevOps Rest API使用Powershell获取版本状态(成功,失败)

如何使用Azure DevOps REST API覆盖列表变量?

如何使用Bearer令牌从Azure DevOps调用REST API

使用REST API批准Azure DevOps中的Yaml管道部署

使用REST API设置Azure devops Release管道变量

Azure Devops REST API删除版本

Azure DevOps REST API

使用Rest API从Azure Devops存储库获取文件

使用Azure Devops Rest API跳过阶段不起作用

使用Powershell脚本的Azure Devops Rest API结果循环

Azure DevOps使用REST API调用GetItem

使用Azure DevOps Rest API查找PAT范围

Azure DevOps REST api-使用变量运行管道

使用 Rest API 在 Azure DevOps 中创建新用户

使用 REST API 下载 Azure Devops 存储库的存档

使用 Powershell 的 Azure Devops 审计 rest api 延续令牌

Azure Devops REST API 删除

如何以角度使用 Azure devops REST API

如何使用 REST API 在 Azure DevOps 中禁用分支策略?

无法使用 Postman 从 Azure Devops rest API 下载附件

使用 PKCE 的 Azure DevOps REST API 身份驗證

如何使用 Azure Devops Services Rest API 在 Azure Devops 中更新测试用例的“区域路径”