5
votes

I'm using the REST API for VSTS to kick off a release for a specific environment. Retrieving the environment and such works, however, when I make the REST call to actually start the deployment, I get the following error message:

[DBG]: PS C:\Users\mmulhe200>> 
executeRequest : {"$id":"1","innerException":null,"message":"Environment with ID '16' is not valid. Valid environments have IDs 
'1288,1289'. Specify a valid environment and try 
again.","typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, 
Microsoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000}
At C:\Users\mmulhe200\Desktop\VSTS release task\test\Untitled1.ps1:58 char:12
+     return executeRequest $request;
+            ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,executeRequest

What's interesting about that is the response from the REST operation to retrieve a release definition with its environments returns such:

...
"id": 16,
"name": "Environment 2",
"rank": 2,
...

In fact, in the entire response, I can't find the ID 1288 nor 1289 anywhere. Any thoughts on why VSTS is telling me my environment ID of 16 is wrong even though it's what's returned from their service?

2

2 Answers

0
votes

The release defintion environment id is not the same thing as the release environment id, could that be the problem?

Make sure you are getting the id from _apis/release/releases/{releaseid} and not _apis/release/definitions/{definitionid}

Also the documentation on https://www.visualstudio.com/en-us/docs/integrate/api/rm/releases#start-deployment-on-an-environment seems to leave out exactly what is required to trigger a deploy onto an environment. It says to PATCH {"status":"inprogress"} but the request actually needs to be PATCH {"status":2}

0
votes

This is the way to see the environment ID on the page. It would be great to display this on the tooltip or on the page. This is what it takes.

Step 1 Open chrome inspection tool

Step 2 Click on the environment

Step 3 Get the related id

enter image description here