有没有办法下载特定的TFS构建日志?我们正在使用TFS 2013.
我已经尝试过使用IBuildDetail但却失败了。
THX。
答案 0 :(得分:0)
您可以使用menthod“Get Build”。它返回IBuildDetail,使用IBuildDetail.LogLocation属性获取此构建的日志文件。最后下载或查询它。以下是演示代码:
publicstaticvoid GetBuildLogAndReadThroughTheLog()
{
// Get all the team projects using the TFS API
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(ConfigurationManager.AppSettings["TfsUri"]));
var versionControlService = tfs.GetService<VersionControlServer>();
var teamProject = versionControlService.GetAllTeamProjects(false)[0];
// Use the build service to get build details for a team project
var buildService = tfs.GetService<IBuildServer>();
// Get the build details
var build = buildService.QueryBuilds(teamProject.Name)[0];
// Get the location of the build Log
var buildLogLocation = build.LogLocation;
// Get the log file
var logFile = versionControlService.GetItem(buildLogLocation);
// Do you want to download the file to a local path?
TextReader tr = new StreamReader(logFile.DownloadFile());
string input = null;
while ((input = tr.ReadLine()) != null)
{
}
}
}
整个构建日志可以在Tbl_BuildInformation中的Tfs_YourTeamProjectCollection数据库中找到。您还可以从DataBase查询并获取它 更多方法供您参考:https://paulselles.wordpress.com/2013/11/15/tfs-build-log-querying-build-log-data/
<强>更新强>
使用“StreamReader”将逐行读取日志文件。
using (StreamReader sr = new StreamReader(buildLogLocation)
{
while (sr.Peek() >= 0)
{
// do your work here...
}
}