Azure DevOps REST API를 사용한 릴리스 정의 업데이트가 이전 복사본으로 실패 함

Aug 21 2020

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})

업데이트를 성공적으로 수행하는 데 필요한 다른 변경 사항이 있습니까?

답변

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.