【问题标题】:How to get scriptable build definitions using Team Foundation Server object model?如何使用 Team Foundation Server 对象模型获取可编写脚本的构建定义?
【发布时间】:2015-12-25 10:41:54
【问题描述】:

是否可以使用常规对象模型获取 Team Foundation Server 2015 新构建定义,还是我必须使用 REST API 获取它们?

如果可以使用对象模型,我应该使用什么类?

我能够使用 IBuildServer.QueryBuildDefinitions 获取 XAML 构建定义。是否有与此方法等效的方法,以便我可以访问新的构建定义及其变量?

【问题讨论】:

    标签: c# tfs build tfsbuild tfs-2015


    【解决方案1】:

    您正在寻找 Build 2.0 REST API。 documentation can be found here

    有一个客户端包装器作为新 NuGet 包的一部分提供,Microsoft.TeamFoundation.Build2.WebApi 程序集提供了一个 BuildHttpClient 对象,它是访问新构建系统的起点。

    【讨论】:

    • 谢谢,我去看看BuildHttpClient
    • 好吧,我得到了整个包裹<package id="Microsoft.TeamFoundationServer.Client" version="14.83.2" targetFramework="net452" />。有没有关于如何使用这些包装器的文档? :D
    • 我怀疑你也需要 ExtendedClient:nuget.org/packages/…
    • 是的,请注意,这个新架构仍在不断发展,您制作的东西可能需要在未来更新
    【解决方案2】:

    您可以使用Microsoft.TeamFoundation.Build.WebApi.BuildHttpClient 获取构建定义:

            var cred = new VssCredentials(new WindowsCredential(new NetworkCredential("{userid}", "{password}")));
            string collectionURL = "http://{tfs-server-url}:8080/tfs/{collection-name}";
            var buildClient = new BuildHttpClient(new Uri(collectionURL, UriKind.Absolute), cred);
    
            //this is the source project's build definition
            //http://{tfs-server-url}:8080/tfs/{collection-name}/{project-name}/_build?_a=completed&definitionId={buildDefId}
            var buildDefId = 20;
            //"http://{tfs-server-url}:8080/tfs/{collection-name}/{project-name}";
            var projectName = "{project-name}";
            var buildDef = (await buildClient.GetDefinitionAsync(projectName, buildDefId)) as BuildDefinition;
    
            Console.WriteLine(buildDef.Name);//here you can get all the other properties
    

    VssCredentials 类来自Microsoft.VisualStudio.Services.Common 程序集。将所有{...} 替换为您的参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-18
      • 2010-10-03
      • 2013-07-02
      • 1970-01-01
      • 2012-04-17
      • 2012-04-28
      • 1970-01-01
      相关资源
      最近更新 更多