microsoft / azure-devops-dotnet-samples

.NET/C# samples for integrating with Azure DevOps Services and Azure DevOps Server
https://docs.microsoft.com/azure/devops/integrate
MIT License
522 stars 519 forks source link

How can I get the Environments status ? #129

Open ThorstenBruegge opened 6 years ago

ThorstenBruegge commented 6 years ago

Hey there,

I need to get the status of the environments. Something like: "inProgress", "failed", "succeeded"

When I use an http-request I can see the status

[...]
"environments": [
    {
      "id": 69,
      "releaseId": 18,
      "name": "Dev",
      "status": "inProgress",
      [...]
    }

But now I want to use this official client library. I tried to get the info like this:

var releaseClient = Connection.GetClient<ReleaseHttpClient>();

var release = releaseClient.GetReleaseDefinitionsAsync(projectName, expand: ReleaseDefinitionExpands.Environments).Result;

But here is no status in there. Is there a way to do it?

ThorstenBruegge commented 6 years ago

Ok. Here are two problems:

releaseClient.GetReleaseDefinitionsAsync(projectName, expand: ReleaseDefinitionExpands.Environments)

First, I can't see the Environments status. Second, the ReleaseID and EnvironmentsID is wrong!

So first of all, I had to get the correct ReleaseID to get every release for it's own. Than can find the Environments status:

`// get a client for Release request var releasesClient = Connection.GetClient(); var releases = releasesClient.GetReleaseDefinitionsAsync(projectName, expand: ReleaseDefinitionExpands.Environments).Result;

        var releaseList = new List<Release>();

        foreach (var item in releases)
        {
            var releaseId = item.Environments.FirstOrDefault().CurrentReleaseReference.Id;

            var releaseDetails = releasesClient.GetReleaseAsync(projectName, releaseId).Result;

            releaseList.Add(releaseDetails);
        }`