Scheduling a release waiting for approval via DevOps API

Viewed 57

I need to schedule a release deployment via Azure DevOps' API.

The release is pending approval and via the interface I can schedule the deployment:

image

Via the API there is no option for it (documentation).

The only options I have are approved, canceled, pending, reassigned, rejected, skipped or undefined.

So I tried to patch the release environment itself (documentation) by changing it to "scheduled":

PATCH https://vsrm.dev.azure.com/jato-jaas/Services/_apis/Release/releases/{releaseId}/environments/{environmentId}?api-version=6.0-preview.6

{
    "status": "scheduled",
    "scheduledDeploymentTime": "2022-06-28T16:00:00Z",
    "variables": {},
    "comment": "Automated deployment"
}

When I call the API I receive this response: Transitioning of stage from state 'InProgress' to state 'Scheduled' is not allowed.

How can I schedule a release that is waiting for approval via the API? I know how to "start" a release with a schedule, but this is not what I need.

1 Answers

Ok, so, I found the solution.

You need to change the release schedule without changing the status (doesn't make sense, but works).

So, you need to call the release environment patch API (https://vsrm.dev.azure.com/jato-jaas/Services/_apis/Release/releases/{releaseId}/environments/{environmentId}?api-version=6.0-preview.6) with a JSON like this:

{
    "scheduledDeploymentTime": "2022-06-28T16:00:00Z",
    "comment": "Automated deployment"
}

You'll receive a propper 200 response but no mention at all in the response about the scheduled time but if you request information about the release you'll find the scheduled time set in the response.

So, call GET https://vsrm.dev.azure.com/jato-jaas/Services/_apis/release/releases/{releaseId}?api-version=6.0 and you'll find it in the environment data (scheduledDeploymentTime).

enter image description here

I believe this is exactly what I found here but for DevOps.

Related