Overview
A lot of people like the idea of continuous integration within their company. I have found it to be necessary for more than just testing builds on check-in. My primary use for it is publishing builds to servers and deployment. This article explains how to set up CruiseControl.Net with an Asp.Net solution and two projects. One verifying builds and automatically building on check-in; the second which requires the build to be forced and publishes the application to a server.
Installation
We need a few things on the build server to start out. Download the tools below if you don't have them.
* CruiseControl.Net - http://sourceforge.net/projects/ccnet/
* NAnt - http://sourceforge.net/project/showfiles.php?group_id=31650&package_id=23704
* Web Deployment Project – Download Here
Note: My particular configuration has .Net Framework 3.5 as well as some other build specific applications. Verify that you have all of the software required for command line builds installed on your integration server.
Run the CruiseControl.Net installer as well as the NAnt installer.
Configuration
Once both installers are done, find the location where you installed CruiseControl.Net and open up the ccnet.config file. Here is a good start for a configuration.
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
<!-- Basic project to verify build on every checkin -->
<project name="(Build) MyProject" queue="MyProjectQueue" queuePriority="1">
<workingDirectory>C:\ccnet\projects\MyProject\work</workingDirectory>
<artifactDirectory>C:\ccnet\projects\MyProjectBuild\artifact</artifactDirectory>
<sourcecontrol type="svn">
<executable>C:\Program Files\SlikSvn\bin\svn.exe</executable>
<trunkUrl>svn://pathToSvnRepo/MyProject/trunk</trunkUrl>
<username>SubversionUser</username>
<password>Password</password>
</sourcecontrol>
<tasks>
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe</executable>
<projectFile>MyProject.sln</projectFile>
<buildArgs>/p:Configuration=Debug</buildArgs>
<targets>Clean;Build</targets>
<logger>C:\ccnet\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
</msbuild>
</tasks>
</project>
<!-- Publish project using web depoloyment and move to server -->
<project name="(Publish) MyProject" queue="MyProjectQueue" queuePriority="2">
<workingDirectory>C:\ccnet\projects\MyProject\work</workingDirectory>
<artifactDirectory>C:\ccnet\projects\MyProjectPublish\artifact</artifactDirectory>
<triggers />
<sourcecontrol type="svn">
<executable>C:\Program Files\SlikSvn\bin\svn.exe</executable>
<trunkUrl>svn://pathToSvnRepo/MyProject/trunk</trunkUrl>
<username>SubversionUser</username>
<password>Password</password>
</sourcecontrol>
<tasks>
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe</executable>
<projectFile>MyProject.sln</projectFile>
<buildArgs>/p:Configuration=Release</buildArgs>
<targets>Clean;Build</targets>
<logger>C:\ccnet\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
</msbuild>
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe</executable>
<projectFile>MyProject.Deployment.wdproj</projectFile>
<buildArgs>/p:Configuration=Release</buildArgs>
<logger>C:\ccnet\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
</msbuild>
<nant>
<executable>C:\nant-0.86-beta1\bin\nant.exe</executable>
<nologo>true</nologo>
<buildFile>C:\ccnet\projects\antscripts\Publish.build</buildFile>
<buildArgs>-D:sourceDir=C:\Inetpub\MyProject -D:targetDir=PathToServer</buildArgs>
<logger>NAnt.Core.XmlLogger</logger>
</nant>
</tasks>
</project>
</cruisecontrol>
Here is the rundown. The first project pulls the source down and builds it automatically whenever it detects a commit to the subversion server. This allows you to see whenever a build is broken. The second project is pretty cool. The <triggers /> tag says that this build must be forced. It pulls from the same repository, except it builds for release. It then runs the web deployment project which changes the web.config to be configured for release. The build is published, and the ant script moves the publish from local IIS to the hosting server.
A few notes. Notice the queuePriority tag? Since both projects use the same source control, I put them in a queue so they don’t try to build off of the same folder at the same time. Also, it is worth looking into the web deployment project. It allows you to configure different application settings for different build types.
As for the ant script? Here you go:
<?xml version="1.0"?>
<project name="Publish to server" default="publish-to-server">
<target name="publish-to-server">
<echo message="Connecting with server" />
<exec program="net.exe"
commandline="use \\server\location /user:un pw" />
<echo message="Publish ${sourceDir} to ${targetDir}" />
<delete dir="${targetDir}" />
<mkdir dir="${targetDir}" />
<move todir="${targetDir}">
<fileset basedir="${sourceDir}">
<include name="**" />
</fileset>
</move>
</target>
</project>
This is assuming that you have network access to your server. If you need to do ftp or something of the like, you should look into ftp with ant scripts. Basically this script connects to the server, removes the current directory, and copies over the publish information.
Thanks to Joe Lombrozo for figuring out the ant script.
Currently rated 3.0 by 1 people
- Currently 3/5 Stars.
- 1
- 2
- 3
- 4
- 5
cruisecontrol.net