1
votes

I'm trying to leverage the DevOps API to update a new release definition. Ultimately, I will be adding a new environment to the release definition but for now I'm just trying to get the update (PUT) method to work.
I've referenced post this post for information.

The code below gets an existing release definition (id=15), bumps the revision, removes the lastRelease property and then makes a change to the description just to change something.

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

The az rest --method put throws an error code complaining that the release is an old copy. I pulled the request from the same version of the API and made changes as describe above. So I'm thinking this new revision is a fresh, new version of the pipeline.

az : Bad Request({"$id":"1","innerException":null,"message":"You are using an old copy of the release pipeline. Refresh your copy and try again.","typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000})

Are there other changes that are required to successfully make the update?

1
Can u debug it and paste definition15 var before and after changes?Tomasz Kaniewski

1 Answers

0
votes

Remove the $rev++, we don't and we shouldn't change the value of revision manually.

Note: If you read the post carefully, you would see I set the revision number to be the number it is currently on and it works now. So we actually doesn't need to change it, the error You are using an old copy of the release pipeline always results from the change of revision.