azure-devopsazure-pipelinesazure-devops-rest-api

How do I filter releases for a specific Environment (Stage)?


I am trying to query the Azure DevOps Rest API to get the current and previous build for each environment for my app.

I am able to get the current build for each environment by calling the /release/definitions endpoint with the environment expand option, then grabbing the currentRelease from the response from each environment to get the ids, then getting those releases by the id to get the build.

For the previous build, I was hoping to call the /release/releases endpoint to filter by the environment id, but when I pass the environment id to the definitionEnvironmentId param on that endpoint, I get 0 results.

How can I filter the /release/releases endpoint to only get releases to the specific environment in question?

Here are the two releases endpoints I am using:


Solution

  • I was able to get the last 2 releases where a particular stage (aka environment) was deployed using the following request using Rest Client (VS Code extension):

    @organization = xxxxxxxxx
    @project = yyyyyyyyyy
    @definitionId = 3
    @definitionEnvironmentId = 6
    
    @apiVersion = 7.1
    @token = zzzzzzzzzzzzzzz
    
    #########################################################################
    
    GET https://vsrm.dev.azure.com/{{organization}}/{{project}}/_apis/release/releases
      ?definitionId={{definitionId}}
      &definitionEnvironmentId={{definitionEnvironmentId}}
      &idDescending=true
      &$top=2
      &$expand=environments
    Accept: application/json; api-version={{apiVersion}}
    Content-Type: application/json
    Authorization: Bearer {{token}}
    

    You might need to add or change the filters to better suit your needs.

    Please note that I'm expanding the environments and returning only 2 results, sorted by ID descending (i.e. last releases first).

    Also, double-check you're using the right values for the definitionId and definitionEnvironmentId parameters - you can find them in the URL, when editing the stage definition:

    See parameters