次の方法で共有


Adding a Fake Build to the Team Build Server

Why would anyone want to add a fake a build to the team build server? Well, there is one very big reason - Integration with Team System. If you don't use Team Build V1 to build your sources (for whatever reason), you may want to at least store some build information in the Team Build server. This allows you to publish test results, associate work items with builds, and view your build information from within Visual Studio.

I saw an older post by someone else that had most of the code. Unfortunately, they were missing the line at the bottom that actually Completes the build. Without this line you won't be able to associate work items with a build number. The code is commented and should be very straight forward. Note that in V1 this process requires several Web Service calls not just one.

So, here is the code:

 using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.TeamFoundation.Build.Proxy;
using Microsoft.TeamFoundation.Client;
using Common = Microsoft.TeamFoundation.Build.Common;

namespace AddFakeBuild
{
    class Program
    {
        static void Main(string[] args)
        {
            AddBuild("https://TeamBuildRTMSP1:8080", "MsfAgile", "FakeBuild001");
        }

        static void AddBuild(String serverName, String teamProject, String buildNumber)
        {
            // Get the TeamFoundation Server
            TeamFoundationServer tfs = new TeamFoundationServer(serverName);

            //Construct build store and build controller objects
            BuildStore bStore = (BuildStore)tfs.GetService(typeof(BuildStore));
            BuildController bController = (BuildController)tfs.GetService(typeof(BuildController));

            //Create a build entry
            BuildData bd = new BuildData();

            //Fill in mandatory information for BuildData object
            bd.BuildNumber = buildNumber;
            bd.BuildType = "DummyBuildType";
            bd.TeamProject = teamProject;

            // Make sure that this drop location exists, otherwise 
            // test publish will fail
            bd.DropLocation = @"\\MySharedMachine\drops\" + buildNumber;
            bd.BuildMachine = "NoBuildMachine";
            bd.RequestedBy = Environment.UserName;

            // These string values are locale dependent in V1
            bd.BuildStatus = Common.BuildConstants.BuildStatus.BuildSucceeded;
            bd.BuildQuality = "Not Examined";

            // Add build entry to TeamBuild DB
            bStore.AddBuild(teamProject, bd);

            // Get the URI of the build
            string buildUri = bStore.GetBuildUri(teamProject, buildNumber);

            // Create platform/flavor information against which the test 
            // results will be published
            ProjectData pd = new ProjectData();

            // Fill in mandatory information for ProjectData object
            pd.FlavourName = "Debug";
            pd.PlatformName = "x86";
            pd.ProjectFile = "Dummy.sln";

            // Add project data entry for this build.
            bStore.AddProjectDetailsForBuild(buildUri, pd);

            // Fill in the finish time
            bStore.UpdateBuildFinishTime(buildUri, DateTime.Now);

            // Complete the build and fire the BuildCompletion Event
            bController.BuildCompleted(buildUri);
        }
    }
}

In my next post, I will show you how to do this in Orcas!

Comments

  • Anonymous
    May 22, 2007
    Srikanth R on New Version Control features in Orcas. Jason Prickett on Adding a Fake Build to the Team...

  • Anonymous
    July 06, 2007
    In my last post about creating a Fake build , I gave you the code to create a fake build in V1 and I

  • Anonymous
    July 09, 2007
    Hi is it possible to take it one step further and associate the changesets since last build to this fake build? Regards Kim

  • Anonymous
    July 18, 2007
    Hi Kim, Yes this is possible, but requires a lot of code. We house that code in our GenCheckinNotesUpdateWorkItems task. You might be able to load that task and call it from your "fake" build code. I haven't tried it, but that would be my first thought. Let me know if you find a better way. Thanks, Jason

  • Anonymous
    July 19, 2007
    Bonjour à tous et à toutes. Team Foundation server n'ai pas qu'une simple application. Tous les développeurs

  • Anonymous
    October 01, 2007
    Hi there! I tried to publish test results using this method but it failed, presumably because there was no directory in the drops folder with the name of the build. I manually added it and it worked! Hope it helps, Alan