如何比较 Azure 库变量组中的变量

How to Compare Variables in the Azure Library-Variable Group

我为我的 Test-Demo-Main 环境设置了变量组,其中有很多变量。所以在进行每个部署之前,我需要将每个部署与每个环境进行比较。现在我正在检查使用控制台应用程序自动执行此过程的可行性。 您能否分享您的 idea/thoughts 关于如何从每个环境中获取所有变量并与其他环境进行比较的方法。

您可以使用SDK来完成这些操作;

库:

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

从组中获取变量的示例:

    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

参考资料:

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

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

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