从TFS web api或TFS通信构建管理器获取最近30天的触发构建定义 [英] Get last 30 days old triggered build definitions from TFS web api or TFS communication build manger

查看:61
本文介绍了从TFS web api或TFS通信构建管理器获取最近30天的触发构建定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用tfs的api 2.0和来自TFS WEB API的我想提取最后一次执行构建定义说所有项目的最后90天但我无法得到它TFS以及TFS web API,我得到了一些来自
的帮助
Leon
&
Alistair
但是从TFS通信构建管理器我得到的列最后一次修改,但事实并非如此,我需要最后触发的构建定义,并且该列不存在于TFS通信构建管理器中,但该列存在于TFS web
API中,但我无法从那里获取信息 

I am using api 2.0 of tfs and from TFS WEB API I want to extract last execution build definitions say last 90 days from all project but I could not get it TFS as well as TFS web API, I got some help from Leon and Alistair but from TFS communication build manger I am getting column last modified but that is not true, I need last triggered build definitions and that columns is not present in TFS communication build manger but the column is present in TFS web API, but I am unable to get the information from there 

我需要这些信息,因为我正在回收构建defini tions和我想要旧的def列表已经触发30天和之前,在获得所有后我将手动或通过脚本禁用它

I need this information because I am recycling build definitions and I want list of old def have triggered 30 days and before, after getting all I will disable it manually or by script 




推荐答案

您好xmangogo,

Hi xmangogo,

感谢您在此发帖。

我们无法直接针对构建定义实现这一点,您可以尝试从构建中检索所需的信息。

We cannot achieve that against the build definition directly, you can try to retrieve the needed info from build.

您可以使用TFS API / Client API来获取构建包含构建
FinishTime 的详细信息,然后相应地过滤它们。

You can use TFS API/Client API to get the build details which including the build FinishTime, then filter them accordingly.

您可以参考以下代码来枚举每个团队项目并获取每个定义的最新构建状态:

You can reference below code which enumerates each team project and gets the latest build status for each of the definitions:

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://tfs:8080"));

var vcs = tfs.GetService<VersionControlServer>();

var teamProjects = vcs.GetAllTeamProjects(true);

IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));

foreach (TeamProject proj in teamProjects)
{
    var defs = buildServer.QueryBuildDefinitions(proj.Name);

    System.Console.WriteLine(string.Format("Team Project: {0}", proj.Name));

    foreach(IBuildDefinition def in defs)
    {
        IBuildDetailSpec spec = buildServer.CreateBuildDetailSpec(proj.Name, def.Name);
        spec.MaxBuildsPerDefinition = 1;
        spec.QueryOrder = BuildQueryOrder.FinishTimeDescending;

        var builds = buildServer.QueryBuilds(spec);

        if (builds.Builds.Length > 0)
        {
            var buildDetail = builds.Builds[0];

            System.Console.WriteLine(string.Format("   {0} - {1} - {2}", def.Name, buildDetail.Status.ToString(), buildDetail.FinishTime));
        }                
    }

    System.Console.WriteLine();
}

相关主题:
TFS API - 如何查询构建独立于它们所属的构建定义

最诚挚的问候。


这篇关于从TFS web api或TFS通信构建管理器获取最近30天的触发构建定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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