Mike Parks

"If you want to be the best, you've got to work with the best"
posts - 26, comments - 101, trackbacks - 0

My Links

News

Archives

Monday, August 03, 2009

Team Build - Deploying To Multiple Environments

Using TFS and Team Build to deploy to Development, Integration, QA, Stage, Pre Production, or any other testing servers you have can be quite a bit of a challenge sometimes. I haven't really found a lot of documentation or best practices out there for it either. There are plenty of ways to move the files across each environment. I'm going to try this build definition out for a while and see how well it works. 

When I queue a new build definition up, I'm going to pass in the following parameters (they will be different each time I queue a new build so I can specify exactly what I need):
/p:GetVersion=C1306
/p:DeployTo=Dev



These parameters are used to tell my build definition which source control version I want to build and which environment I want to deploy the files to.  The GetVersion parameter can accept a changeset number, label, date, "W" (Version last fetched to your workspace), or "T" (latest version).  The DeployTo parameter can accept Dev, QA, or Stage. You can also default the parameters by setting the values in the .rsp file. See the following links for more information on how these are being used:

Building a Specific Version with Team Build 2008
MSBuild Conditional Constructs

Here's a sample build definition that uses the parameters:

<?xml version="1.0" encoding="utf-8"?>

<!-- DO NOT EDIT the project element - the ToolsVersion specified here does not prevent the solutions

     and projects in the SolutionToBuild item group from targeting other versions of the .NET framework.

     -->

<Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">

  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets" />

 

  <ProjectExtensions>

    <ProjectFileVersion>2</ProjectFileVersion>

    <Description></Description>

    <BuildMachine>TFSRTM08</BuildMachine>

  </ProjectExtensions>

 

  <PropertyGroup>

    <TeamProject>MikeTFS</TeamProject>

    <BuildDirectoryPath>c:\bw\-1</BuildDirectoryPath>

    <DropLocation>\\UNKNOWN\drops</DropLocation>

    <RunTest>false</RunTest>

    <RunCodeAnalysis>Never</RunCodeAnalysis>

    <WorkItemType>Bug</WorkItemType>

    <WorkItemFieldValues>System.Reason=Build Failure;System.Description=Start the build using Team Build</WorkItemFieldValues>

    <WorkItemTitle>Build failure in build:</WorkItemTitle>

    <DescriptionText>This work item was created by Team Build on a build failure.</DescriptionText>

    <BuildlogText>The build log file is at:</BuildlogText>

    <ErrorWarningLogText>The errors/warnings log file is at:</ErrorWarningLogText>

    <UpdateAssociatedWorkItems>true</UpdateAssociatedWorkItems>

    <AdditionalVCOverrides></AdditionalVCOverrides>

    <CustomPropertiesForClean></CustomPropertiesForClean>

    <CustomPropertiesForBuild></CustomPropertiesForBuild>

    <SkipWorkItemCreation>true</SkipWorkItemCreation>

  </PropertyGroup>

 

  <Choose>

    <When Condition=" '$(DeployTo)'=='Dev' ">

      <PropertyGroup>

        <DeployPath>\\MikesDevServer\Websites\MikesWebApplication</DeployPath>

      </PropertyGroup>

    </When>

    <When Condition=" '$(DeployTo)'=='QA' ">

      <PropertyGroup>

        <DeployPath>\\MikesQAServer\Websites\MikesWebApplication</DeployPath>

      </PropertyGroup>

    </When>

    <When Condition=" '$(DeployTo)'=='Stage' ">

      <PropertyGroup>

        <DeployPath>\\MikesStageServer\Websites\MikesWebApplication</DeployPath>

      </PropertyGroup>

    </When>

  </Choose>

 

  <ItemGroup>

    <SolutionToBuild Include="$(BuildProjectFolderPath)/../../Development/Websites/MikesWebApplication/MikesWebApplication.sln">

      <Targets></Targets>

      <Properties></Properties>

    </SolutionToBuild>

  </ItemGroup>

 

  <ItemGroup>

    <ConfigurationToBuild Include="Release|Mixed Platforms">

      <FlavorToBuild>Release</FlavorToBuild>

      <PlatformToBuild>Mixed Platforms</PlatformToBuild>

    </ConfigurationToBuild>

  </ItemGroup>

 

  <Target Name="AfterDropBuild" >

   

    <!--Delete Previous Deployment-->

    <CreateItem Include="$(DeployPath)\**\*.*" Exclude="$(DeployPath)\**\Web.Config">

      <Output ItemName="PreviousDeployment" TaskParameter="Include" />

    </CreateItem>

    <Delete Files="@(PreviousDeployment)" ContinueOnError="true" />

 

    <!--Define New Deployment Files To Be Copied-->

    <ItemGroup>

      <Compile Include="$(DropLocation)\$(BuildNumber)\Mixed Platforms\Release\_PublishedWebsites\**\*.*"

               Exclude="$(DropLocation)\$(BuildNumber)\Mixed Platforms\Release\_PublishedWebsites\**\Web.Config"/>

    </ItemGroup>

   

    <!--Deploy-->

    <Copy SourceFiles="@(Compile)" DestinationFolder="$(DeployPath)\%(RecursiveDir)"></Copy>

   

  </Target>

</Project>


Hope this helps! Leave me some feedback if you get a chance. Thanks everyone.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Monday, August 03, 2009 11:20 PM | Feedback (0) |

Team Build - Delete All Files - Include and Exclude

A few days ago I needed to delete all files except for web.configs out of a deployment folder using Team Build.  I added the code below to the build definitions .proj file.  It's a quick and easy way to clean out some, but not all, of the files in the deployment folder. You can use wildcards in the CreateItem tag.  It's not perfect because it isn't made to deal with deleting empty sub folders but it got the job done for what I needed.

  <PropertyGroup>

    <DeployPath>\\MikesServer\Websites\TestWebsite</DeployPath>

  </PropertyGroup>
 

  <Target Name="AfterDropBuild" >

    <CreateItem Include="$(DeployPath)\**\*.*" Exclude="$(DeployPath)\**\Web.Config">

      <Output ItemName="PreviousDeployment" TaskParameter="Include" />

    </CreateItem>

    <Delete Files="@(PreviousDeployment)" ContinueOnError="true" />

  </Target>

 

 

There are a few other ways you can clean out a folder. The delete task is the one I used above. An easy way to delete everything is to use the <RemoveDir Directories="$(OutputPath)\dir" /> and <MakeDir Directories="$(OutputPath)\dir" /> tags. You can also use a MSBuild tasks library such as SDC Tasks and use the CleanFolder task to delete everything in a folder.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Monday, August 03, 2009 10:43 PM | Feedback (0) |

Powered by: