Поделиться через


Customizing Team Build 2010’s Drop Location Algorithm

One of the properties you specify when creating a new build definition is the build’s drop location. However, this isn’t a statically defined drop location (because if it was each build would overwrite the previous build).

Team Build 2008’s drop location algorithm took the drop location you specified and appended the build number. This generally worked fine except if you had two build definitions dropping to a single folder and you customized the build number generation algorithm to not include the build definition name in the build number.

To work around this Team Build 2010’s drop location algorithm appends both the build definition name and the build number to the drop location. This guarantees uniqueness in the path and will prevent builds overwriting each other and gives you an out-of-the-box solution that just works even if you customize the build number generation algorithm (which is easier in Team Build 2010 than it as in Team Build 2008).

The downside to this new algorithm is if you want to have complete control over the drop location’s structure. For example, lets say you have two build definitions MyApp_Main and MyApp_v1 configured to drop to \\builds\apps\MyApp, the default drop location algorithm will produce this structure:

  • \\builds\apps\MyApp
    • MyApp_Main
      • MyApp_Main_20091216.1
      • MyApp_Main_20091216.2
      • etc.
    • MyApp_v1
      • MyApp_v1_20091216.1
      • MyApp_v1_20091216.1
      • etc.

If I want this (less redundant) structure instead that I’ll have to customize the build process template:

  • \\builds\apps\MyApp
    • Main
      • 20091216.1
      • 20091216.2
    • v1
      • 20091216.1
      • 20091216.2

So let’s do that:

  1. Branch a copy of BuildProcessTemplates\DefaultProcessTemplate.xaml.
    1. Never edit the DefaultProcessTemplate.xaml directly. You’ll want to keep the original template to refer to, diff against, and to assist when applying service packs with updated build process templates.
  2. Checkout and open the branched copy of DefaultProcessTemplate.xaml.
  3. Right-click the Set Drop Location activity (Process\Sequence\Update Drop Location\If Drop Build And Reason is Triggered\Sequence\Set Drop Location) and click Properties.
  4. Change the DropLocation property from BuildDetail.DropLocationRoot + "\" + BuildDetail.BuildDefinition.Name + "\" + "BuildDetail.BuildNumber to BuildDetail.DropLocationRoot + "\" + If(BuildDetail.BuildNumber.StartsWith(BuildDetail.BuildDefinition.Name + "_"), BuildDetail.BuildNumber.Remove(0, BuildDetail.BuildDefinition.Name.Length + 1), BuildDetail.BuildNumber).
  5. Configure your build definition to use the branched copy of DefaultProcessTemplate.xaml.

Basically all we’re doing in step #4 is removing the BuildDetail.BuildDefinition.Name directory from the drop location structure and trimming the build definition name (and trailing underscore) off the beginning of the final directory in the drop location structure. If you’ve customized your build number format you’ll need to modify this trimming algorithm to suit.