Azure DevOps RESTAPIを使用したUpateリリース定義が古いコピーで失敗する

Aug 21 2020

DevOpsAPIを活用して新しいリリース定義を更新しようとしています。最終的には、リリース定義に新しい環境を追加しますが、今のところ、更新(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})

更新を正常に行うために必要な他の変更はありますか?

回答

LanceLi-MSFT Aug 24 2020 at 09:28

削除$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。の変更によって発生します。