Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use the TFS SDK to create, queue and track builds?

I've been googling and can't find any solid examples how this is done, or if it even can be done. I assume it can. Can anyone point me in the right direction?

So far I've been looking under the TFS namespace documentation on msdn. My goal is to be able to fully automate and track our builds in TFS from an intranet web application.

like image 306
JimDaniel Avatar asked Mar 04 '09 16:03

JimDaniel


2 Answers

Richard pointed me in the right direction, so I'm going to answer my own question with what I've found.

Yes, you can use the TFS SDK to create, queue, and track builds. The interfaces/classes you want are located in the Microsoft.TeamFoundation.Build.Client namespace. IBuildServer, IBuildDefinition, and IBuildDetail are particularly useful.

TFS 2010 UPDATE: Here is an example program using the TFS 2010 SDK, found here:

using System;
using System.Collections.Generic;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Build.Workflow;
using Microsoft.TeamFoundation.Client;

namespace ManageBuildTemplates
{
    class Program
    {
        static void Main(string[] args)
        {
            TfsTeamProjectCollection collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://jpricket-test:8080/tfs/collection0"));
            IBuildServer buildServer = collection.GetService<IBuildServer>();

            IBuildDefinition definition = buildServer.GetBuildDefinition("UnitTests", "Definition1");

            IBuildRequest request = definition.CreateBuildRequest();
            request.ProcessParameters = UpdateVerbosity(request.ProcessParameters, BuildVerbosity.Diagnostic);

            buildServer.QueueBuild(request);
        }

        private static string UpdateVerbosity(string processParameters, BuildVerbosity buildVerbosity)
        {
            IDictionary<String, Object> paramValues = WorkflowHelpers.DeserializeProcessParameters(processParameters);
            paramValues[ProcessParameterMetadata.StandardParameterNames.Verbosity] = buildVerbosity;
            return WorkflowHelpers.SerializeProcessParameters(paramValues);
        }
    }
}
like image 165
JimDaniel Avatar answered Nov 11 '22 15:11

JimDaniel


Look at tfsbuild.exe (in the .../Common9/IDE folder of the VS install).

This references assemblies Microsoft.TeamFoundation.Build.Client and Microsoft.TeamFoundation.Build.Common which look helpful, ... and contain namespaces which are not documented with the other TFS cient assembliies, but are on MSDN here http://msdn.microsoft.com/en-us/library/cc339575.aspx

like image 45
Richard Avatar answered Nov 11 '22 16:11

Richard