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
523 stars 517 forks source link

How to change variable in a variable group #299

Open PatrickGrub opened 4 years ago

PatrickGrub commented 4 years ago

I want to change via C# in Azure Devops in a specific Variable Group a specific variable: https://docs.microsoft.com/en-us/rest/api/azure/devops/distributedtask/variablegroups?view=azure-devops-rest-5.0

How can I get started? Which VssHttpClientBase do I need? Examples?

ydbendasan commented 3 years ago

You'll need to install Microsoft.TeamFoundation.DistributedTask.WebApi nuget package, reference Microsoft.TeamFoundation.DistributedTask.WebApi

then you can initialise TaskAgentHttpClient

var devopsConnection = new VssConnection(new Uri(devopsUrl), new VssBasicCredential(string.Empty, devopsToken));
var taskClient = devopsConnection.GetClient<TaskAgentHttpClient>();
var variableGroups = taskClient.GetVariableGroupsAsync(project.Id).Result;

then use methods on these to modify as you desire.

DavidBergeron-eng commented 3 years ago

Not impersonating didn't know.