获取构建信息

本文关键字:信息 构建 获取 | 更新日期: 2023-09-27 18:04:00

对于我们新的TFS 2015服务器,我想创建一个网页,您可以在其中看到每次构建的警告计数和代码覆盖率的历史记录。如何获得发生了多少警告以及单元测试覆盖了多少构建代码的信息?我试着通过BuildHttpClient获得构建来找到这一点,但当通过构建类调试时,我没有发现任何具有该信息的属性。以下是我如何获得构建的代码:

    public static Build[] GetRunningBuilds(this BuildHttpClient buildServer, string collectionName)
    {
        return buildServer.GetBuildsAsync(collectionName, statusFilter: BuildStatus.InProgress).Result.ToArray();
    }
    public static Build[] GetFailedBuilds(this BuildHttpClient buildServer, string collectionName)
    {
        var builds = buildServer.GetBuildsAsync(collectionName, statusFilter: BuildStatus.Completed, resultFilter: BuildResult.Failed).Result.ToList();
        builds.AddRange(buildServer.GetBuildsAsync(collectionName, statusFilter: BuildStatus.Completed, resultFilter: BuildResult.PartiallySucceeded).Result);
        return builds.OrderBy(b=>b.FinishTime).ToArray();
    }
    public static DefinitionReference[] GetBuildDefinitions(this BuildHttpClient buildServer, string collectionName)
    {
        var buildDefinitions = buildServer.GetDefinitionsAsync(project: collectionName).Result.ToList();
        return buildDefinitions.ToArray();
    }

获取构建信息

您需要在Microsoft.TeamFoundation.TestManagement.WebApi中使用"GetBuildCodeCoverageAsync"方法来获取代码覆盖率信息。

ITestManagementHttpClient.GetBuildCodeCoverageAsync(string, int, int, object, System.Threading.CancellationToken)

System.Threading.Tasks.Task>GetBuildCodeCoverageAsync(string project, int buildId, int flags)[object userState = null], [System.Threading.CancellationToken .cancellationToken = null])microsoft . teamfoundation . testmanagement . webapi . itestmanagemententhttpclient成员

摘要:发送基于REST的消息到服务器获取代码覆盖率这个API可以被使用

有关标志信息,请参考此链接了解详细信息:获取构建的代码覆盖率数据

要获得代码覆盖率,您需要使用CoverageAnalysisManager

:

TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfs_server_here:8080/tfs/something_here"));
ITestManagementService tcm = (ITestManagementService) tfs.GetService(typeof(ITestManagementService));
ITestManagementTeamProject testManagementTeamProject = tcm.GetTeamProject("team_name_here");
ICoverageAnalysisManager coverageAnalysisManager = testManagementTeamProject.CoverageAnalysisManager;
IBuildCoverage[] queryBuildCoverage = coverageAnalysisManager.QueryBuildCoverage(build.Uri.ToString(), CoverageQueryFlags.Modules);