Dec 15 2009

Deploy Subversion code base into your development environment via CruiseControl.NET

Category: Continuous Integrationryancmartin1976 @ 21:00

First Strategy:

Second Strategy:

Deploy your local code to development for further testing with a click of a button

There are 3 techniques used here to make code deployment seamless for testing in your development environment.

  1. Setup a server to be the development server
  2. Add your project to Subversion
  3. Configure your cruisecontrol.net configuration file and nant build script accordingly

STEP 1

Pick any server to be your development server, potentially one that you use for all projects and sites. This server should mirror your production server, same frameworks, executables and services.

STEP 2

Add your local project to your Subversion server.

STEP 3

Configure the CruiseControl.NET ccnet.config file to call Nant build task without an interval trigger. This assures that the versioned codebase will never get copied over by accident.

<project name="Deploy-To-Development">
  <labeller type="defaultlabeller" />
  <webURL>http://localhost/ccnet/ViewFarmReport.aspx</webURL>
 
  <sourcecontrol type="filtered">
    <sourceControlProvider type="svn" autoGetSource="true">
      <executable>C:\Program Files\VisualSVN Server\bin\svn.exe</executable>
      <trunkUrl>http://domain.com/svn/ProjectName/trunk</trunkUrl>
      <workingDirectory>D:\Projects\compile\ProjectName\trunk</workingDirectory>
      <tagOnSuccess>false</tagOnSuccess>
      <tagBaseUrl>http://domain.com/svn/ProjectName/tags</tagBaseUrl>
      <username>rmartin</username>
      <password>Madison1</password>
    </sourceControlProvider>
    <inclusionFilters>
      <pathFilter>
        <pattern>**/*.*</pattern>
      </pathFilter>
    </inclusionFilters>
  </sourcecontrol>
 
  <tasks>
    <nant>
      <executable>D:\Projects\compile\ProjectName\trunk\binaries\nant\bin\nant.exe</executable>
      <baseDirectory>D:\Projects\compile\ProjectName\trunk\source\</baseDirectory>
      <buildArgs>-D:svn.executable="D:\Projects\compile\ProjectName\trunk\binaries\subversion\svn.exe"</buildArgs>
      <nologo>false</nologo>
      <buildFile>D:\Projects\compile\ProjectName\trunk\Build\ProjectName.build</buildFile>
      <targetList>
        <target>deploy-to-development</target>
      </targetList>
      <buildTimeoutSeconds>1200</buildTimeoutSeconds>
    </nant>
  </tasks>
 
  <publishers>
    <merge>
      <files>
        <file>C:\Program Files\CruiseControl.NET\server\Deploy-To-Development\Artifacts\results.xml</file>
      </files>
    </merge>
    <xmllogger />
    <statistics />
    <email
      from="ProjectNameBuild@domain.com"
      mailhost="mail.domain.com" includeDetails="TRUE">
      <users>
        <user name="Ryan Martin" group="buildmaster" address="rmartin@domain.com"/>
      </users>
      <groups>
        <group name="buildmaster" notification="always"/>
      </groups>
    </email>
  </publishers>
</project>

Next setup the NAnt build script to run a task that does the deployment

<?xml version="1.0" encoding="utf-8"?>
<project name="IpswitchftWeb" default="build" xmlns="http://nant.sf.net/release/0.85/nant.xsd">
  <!-- Properties -->
  <property name="devserver.website.dir" value="D:\Projects\www\ProjectName"/>
  <property name="trunk.dir" value="..\" />
  <property name="source.dir" value="${trunk.dir}\Source" />
  <property name="msbuild.exe" value="C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe" />
  <property name="solution.sln" value="${source.dir}\ProjectNameWeb.sln" />
 
  <!-- Called Externally -->
  <target name="build" depends="compile" />
  <target name="deploy-to-development" depends="compile, deploy.to.development" />
 
  <target name="deploy.to.development">
    <echo message="Deleting all files in development web directory"/>
    <delete verbose="true">
      <fileset basedir="${devserver.website.dir}">
        <include name="*.*" />
      </fileset>
    </delete>
 
    <echo message="XCopy files to development web directory"/>
    <copy todir="${devserver.website.dir}" includeemptydirs="false" overwrite="true">
      <fileset basedir="${ProjectNameWeb.dir}">
        <exclude name="**/obj/**"/>
        <exclude name="**/*.csproj"/>
        <exclude name="**/*.csproj*"/>
        <exclude name="**/App_Data*"/>
        <exclude name="**/App_Data*/**"/>
        <exclude name="**/.svn*"/>
        <exclude name="**/.svn*/**"/>
        <include name="**"/>
      </fileset>
    </copy>
  </target>
</project>

Next run the task from CruiseControl.NET Web Dashboard

This process takes about 30 seconds to 3 minutes depending on the size of the application. You can add all types of files to exclude from the copy over which saves you tons of time in it from doing it manually. This is especially helpful when your project is in Subversion and you have all of those .svn folders everywhere.

Tags: , , ,