Partilhar via


Attaching Custom Data to a Build

In Orcas, we introduced a generic information storage for builds - internally this is used for all build steps, associated changesets/workitems, etc.  You can use it to attach arbitrary data to a build (and later retrieve it).  Here are a couple of quick code snippets to illustrate these two cases.

To attach a single name/value pair to a build, you would do something like this:

         TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsUrl);
        IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
        IBuildDetail buildDetail = buildServer.GetBuild(buildUri);

        IBuildInformationNode node = buildDetail.Information.CreateNode();

        node.Type = "MyCompany.Custom";
        node.Fields["key"] = "value";

        buildDetail.Information.Save();

To retrieve the same name/value pair from the build, you would do something like this:

         TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsUrl);
        IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
        IBuildDetail buildDetail = buildServer.GetBuild(buildUri);

        List<IBuildInformationNode> nodes = buildDetail.Information.GetNodesByType("MyCompany.Custom");

        if (nodes.Count > 0)
        {
            foreach (IBuildInformationNode node in nodes)
            {
                String value = node["key"];

                // Do something...
            }
        }

Note that the information node storage is hierarchical, so you can get a lot fancier than this if you want/need to!  Note that full documentation of the Orcas TFS Build Object Model can be found here.

Comments

  • Anonymous
    September 24, 2008
    Hi Aaron.Any chance in a future release that the Information property might be included in the eventXml sent from a build completion event (perhaps BuildCompletionEvent3 !)That would be handy...Thanks,-Mitch
  • Anonymous
    October 29, 2008
    Arron,Will this information show up anywhere in the default build report? It will also be nice if it does come as part of the eventXml.Regards,Sucharith Vanguri