【问题标题】:Azure DevOps Server object Api get builds by change idAzure DevOps Server 对象 Api 通过更改 id 获取构建
【发布时间】:2020-07-09 15:06:54
【问题描述】:

使用 Azure Pipeline 对象 API,可以获得构建。

BuildHttpClient.GetBuildsAsync(params)

现在我可以获取构建的更改,因为我需要通过特定的更改 id(提交哈希)过滤构建

BuildHttpClient.GetBuildChangesAsync(params, buildId)
// Here I can loop over the changes and search for a specific change id (commit hash)
// But this scales very bad, getting the changes is really slow. Doing this on tousand of builds can take minutes!

有没有办法通过在一个查询中具有特定更改 ID 的 API 来构建?

【问题讨论】:

    标签: azure-devops azure-devops-rest-api


    【解决方案1】:

    你可以从BuildHttpClient.GetBuildsAsync得到sourceVersion和id,直接过滤sourceVersion。 sourceVersion 是 changesetId/CommitId。例如:

            string _personalAccessToken = "xxxxxxxxx";
            VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken);
            var connection = new VssConnection(new Uri(@"https://dev.azure.com/xxxx"), credentials);
            var buildServer = connection.GetClient<BuildHttpClient>();
            var builds = buildServer.GetBuildsAsync($"teamprojectname").Result;
    
            foreach (var build in builds)
            {
                if (build.SourceVersion == "commitID")
                {
                    Console.WriteLine(build.Id);
                }
            }
    

    【讨论】:

    • 这对我们的要求不可靠。如果我们有多个提交,这将不再有效。为此,构建的变更集包含具有任何提交 ID 的任何更改,这正是我们所需要的。另一点是,如果我们在 GetBuildsAsync 参数上设置了一个顶部,那么这将是一个附加过滤器,并且不会返回所需的构建数量......所以我们需要加载更多构建,直到达到顶部,这很难看
    • 如果是这种情况,恐怕您必须像以前那样循环更改。没有默认方式使用 api 通过更改 id 获取构建。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-07
    • 2020-01-13
    • 2019-08-24
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    相关资源
    最近更新 更多