如何从 TFS MS Build 或 TFS API 获取构建警告 [英] How to fetch Build Warning from TFS MS Build or TFS API

查看:27
本文介绍了如何从 TFS MS Build 或 TFS API 获取构建警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 MS Build 中获取构建警告(在包含或具有多个解决方案的构建中)

I am trying to fetch Build Warning from MS Build,(in Build which contain or having number of solutions)

是否可以使用 TFS API 或使用 QUERY 的任何 TFS 数据库来获取?

Is it possible to fetch using TFS API, or any TFS DB using QUERY ?

推荐答案

你可以使用这个 TFS REST API 以获取 TFS 构建的日志.要注销这些日志,您需要自己获取这些警告.没有只接收警告的 API.

You could use this TFS REST API to get logs of a TFS builds. To get those logs out, you need to fetch those warnings by yourself. There's no API to only get warnings.

Http method: GET

http:/servername"8080/tfs/DefaultCollection/teamproject/_apis/build/builds/391/logs?api-version=2.0

您还可以安装 TFS ExtendedClient Nuget 包以使用 TFS对象模型 API.

You could also install a TFS ExtendedClient Nuget package to use TFS object model API.

这是代码片段:

就像上面的评论一样,使用旧版本的 API 无法访问 VNext 构建定义信息.为您的项目安装此 TFS ExtendedClient Nuget 包,使用以下方法获取所有构建定义.

Like the comment said above, the VNext build definition information couldn't be reached using the old version API. Install this TFS ExtendedClient Nuget package for your project, using the method below to get all build definitions.

using Microsoft.VisualStudio.Services.WebApi;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.VisualStudio.Services.Operations;

private static void GetBuildWarnings()
{
    var u = new Uri("http://v-tinmo-12r2:8080/tfs/MyCollection/");
    VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(new NetworkCredential("username", "password", "domain")));
    var connection = new VssConnection(u, c);
    BuildHttpClient buildServer = connection.GetClient<BuildHttpClient>();

    List<BuildLog> logs =  buildServer.GetBuildLogsAsync("teamprojectname",buildId).Result;
    foreach (BuildLog log in logs)
    {
        var list = buildServer.GetBuildLogLinesAsync("A92FB795-A956-45B5-A017-7A7DFB96A040",buildId,log.Id).Result;  //A92FB795-A956-45B5-A017-7A7DFB96A040 is the team project Guid
        foreach (var line in list)
        {
            if (l.Contains("[Warning]"))
            {
                Console.WriteLine(line);
            }
        }
    }
    Console.ReadLine();
}

这篇关于如何从 TFS MS Build 或 TFS API 获取构建警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆