Geeks With Blogs

News
(Amazon Affiliate Ads)

Mike Parks Code.Where(c => c.IsTechnicalDebt).Refactor();
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. Posted on Wednesday, August 5, 2009 3:49 PM | Back to top


Comments on this post: TFS - Deploying To Multiple Environments Using Team Build

# re: TFS - Deploying To Multiple Environments Using Team Build
Requesting Gravatar...
I did something similar, but I separated the build from the deploy so that I could control which TFS users could do the deploy and since you have to give administer a build rights to apply the MSBUILD parameters.
Left by Paul D'Anna on Aug 10, 2009 8:04 PM

Your comment:
 (will show your gravatar)


Copyright © MikeParks | Powered by: GeeksWithBlogs.net