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 to get Release Definition Environment's varables? #75

Closed willbush closed 7 years ago

willbush commented 7 years ago
var connection = new VssConnection(new Uri(VstsCollectioUrl), new VssClientCredentials());
var releaseClient = connection.GetClient<ReleaseHttpClient>();
var defs = releaseClient.GetReleaseDefinitionsAsync("ProjectName", expand: ReleaseDefinitionExpands.Environments).Result;

I can get release release definitions with their environments expanded, but those environments don't have their variables expanded.

One would hope this would work:

var connection = new VssConnection(new Uri(VstsCollectioUrl), new VssClientCredentials());
var releaseClient = connection.GetClient<ReleaseHttpClient>();
var myEnv = releaseClient.GetDefinitionEnvironmentsAsync("MyProject").Result;

However, it throws an exception because the task group ID was not found (an optional param). I am having trouble locating this ID in TFS, and I cannot find any documentation on the GetDefinitionEnvironmentsAsync method.

willbush commented 7 years ago

I couldn't figure out how to do it through the C# API, but it can be done with an http request:

https://www.visualstudio.com/en-us/docs/integrate/api/rm/definitions

GET https://{instance}/{project}/_apis/release/definitions/{definitionId}?api-version={version}

What this documentation doesn't point out is that this is available only with version=3.0-preview

This will return environments expanded and everything in those environments including environmental variables.

bansalaseem commented 7 years ago

You should get a single release definition instead of querying for N definitions and that will give you all the variables. The method name should be something like GetReleaseDefinitionAsync(...)

willbush commented 7 years ago

Thanks for the response. Feel free to close the issue. I did not test what you suggested, but it sounds like it will work. I ended up just parsing the json to get the data I wanted and it was pretty easy to do.

chandan-anjani commented 7 years ago

Closing the issue as per customer comment.