2
votes

I am trying to update release scoped variables for the existing release using API.

Issue: receiving exception on API call (PUT https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=5.1-preview.8)

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"You are using an old copy of release. 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}

Steps to Recreate:

  1. Create release from existing release definition without triggering any stages on the web portal: https://vsrm.dev.azure.com
  2. Get release details by invoking: GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=5.1-preview.8
  3. Update response from step 2 with value for release scoped variable with "allowOverride" set to true
  4. Update response from step 2 with "modifiedOn" property set to later date than existing value
  5. Update response from step 2 with "definitionSnapshotRevision" property set to existing value incremented by 1
  6. Update release by invoking: PUT https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=5.1-preview.8 and providing json generated in steps 2-5
  7. Observe above mentioned exception

I have updated 2 release properties (modifiedOn and definitionSnapshotRevision) because I saw that these values change if I update a release using web site (https://vsrm.dev.azure.com). It seems that I am still missing something. I cannot find any guidance in documentation on how to properly update a release deployment.

1

1 Answers

0
votes

I used "Invoke-RestMethod" powershell commandlet to get release metadata. This commandlet returns custom ps object which I then updated, converted to json using "ConvertTo-Json" commandlet and provided in the body of the PUT HTTP request to DevOps to update the release. The issue is that Powershell serialization/de-serialization process of json does not result to the original json. For example this json property:

"preDeploymentGatesSnapshot": {
    "id": 0,
    "gatesOptions": null,
    "gates": []
},

becomes:

"preDeploymentGatesSnapshot": "@{id=0; gatesOptions=; gates=System.Object[]}"

After I used correct json in the body of the PUT request in the API call:

https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=5.1-preview.8

the release got successfully updated.