Search code examples
c#.netazureazure-devopsconsole-application

How to Compare Variables in the Azure Library-Variable Group


I have Variable Groups set for my Test-Demo-Main environments and I have so many variables in it. so before going for each deployment I need to compare each with each environment. Now I am checking the feasibility to automate this process with a console application. Could you please share your idea/thoughts on how can I get all the variables from each environment and compare with other env.


Solution

  • you can use the SDK to do these operations;

    libs:

    • Microsoft.TeamFoundation.DistributedTask.WebApi
    • Microsoft.TeamFoundationServer.Client
    • Microsoft.VisualStudio.Services.Client
    • Microsoft.VisualStudio.Services.InteractiveClient

    example to get variables from Group:

        Uri _uri = new Uri("https://dev.azure.com/{your org}/");
    
        VssBasicCredential loginCred = new VssBasicCredential("user", "PAT");
    
        VssConnection vssConnection = new VssConnection(_uri, loginCred);
    
        await vssConnection.ConnectAsync();
    
        var taskagent = vssConnection.GetClient<TaskAgentHttpClient>();
    
        var var_env_1 = (await c.GetVariableGroupAsync("projectname", 1)).Variables;
        var var_env_2 = (await c.GetVariableGroupAsync("projectname", 2)).Variables;
        var var_env_3 = (await c.GetVariableGroupAsync("projectname", 3)).Variables;
    
       // 1,2,3 = idgroup, YOU CAN GET THE URL (variableGroupId) WHEN ACCESSING THE GROUP IN AZURE DEVOPS
    
        // LOGIC TO COMPARE
    

    refs:

    https://github.com/microsoft/azure-devops-dotnet-samples/tree/main/ClientLibrary/Samples

    https://learn.microsoft.com/pt-br/azure/devops/integrate/concepts/dotnet-client-libraries?view=azure-devops#samples

    https://learn.microsoft.com/pt-br/azure/devops/integrate/get-started/client-libraries/samples?view=azure-devops