enterprise-sitecore-continuous-integration-and-configuration-management-part-2I want to share a way how to create parameterized builds on Hudson using NAnt technology to deploy .NET projects. This technique is used to build code that is checked on svn tags. The idea is to have a Hudson job that builds code from the trunk (Integration Build), and another Hudson job that builds code from a svn tag.
The first step is to have a well formed SVN repository with the following standard structure:
The folder mainline is going to contain the current code, the folder tags is going to contain the tags of an specific revision taken from the trunk, and branches is going to contain copies of an specific revision taken from the trunk.
The second step is to create the Integration job in Hudson to build from the trunk. The builds executed by this job are the ones used to tag on SVN; in order the QA job builds the code from a specific tag.
In Hudson go to New Job - > Build a free-style software project - > Click Ok.
Here you need to create a Name for the job like “Integration Build Job”, add a description, and configure Hudson as follows:
1. Set subversion repository URL and check the update checkbox.
2. You can setup to build periodically by just configuring the Schedule option.
3. In the build section, choose to “Execute NAnt build”, set the path where the build script is located on your SVN, and configure the parameters that you want to send to your NAnt script.
Note1: If you want to configure Hudson to be integrated with NAnt please check the following link: http://wiki.hudson-ci.org/display/HUDSON/NAnt+Plugin
Note2: The path to the build file is relative to Hudson workspace. When you create a job, Hudson creates a folder in the local machine with the name of the job. So in our case, with this SVN configuration, the code is going to be downloaded into Hudson machine in the location:
<Hudson Home>/jobs/Integration Build Job/workspace/mainline/<CODE>.
Note3: I am assuming that the trunk code structure used for this example is:
Where WebProject is the folder representing a C# Web project included in the solution file Solution.sln, and the file defaultParameterized.build is the Nant Script that Hudson calls to update, compile, and deploy. An example of a NAnt script is in the post:
. Also, the above post suggest how to handle Configuration Manager on SVN and NAnt builds, so please check it first.
Analyzing the parameters that I am sending to the nant script we have:
propertyFile: The name of the properties files.
Environmenttag: The name of the environment under build to choose from the configuration manager folder the correct properties file.
Ftpuser: The ftp user
Ftppass: The ftp password
Ftpsourceprefix: The path to Hudson workspace plus the folder /mainline. In few words, the ftp source folder where the project exist in order to deploy the site.
Ftpdestinationprefix: The ftp destination folder. In this folder should be running an IIS site.
The third step is to create a job for QA build. Basically, you need to do the same configurations done for the Integration job, but in this case you need to check the checkbox “This build is parameterized” like the following:
Notice that the Repository url is using the parameter $tagname. This parameter is the recently defined “String parameter” added into Hudson configuration. $tagname represents which SVN tag Hudson is going to use in order to build.
The “Local module directory” configuration has the configuration “tags”, the reason of this is that Hudson replaces the folder name $tagname to tag in the local folder structure as
<Hudson Home>/jobs/QA Build Job/workspace/tags/<CODE>.
Additional changes needed to do to the parameters that QA job sends to the NAnt script like:
1. environmenttag=QA: This is to apply QA Configuration located in the Configuration Manager.
2. Ftpsourceprefix= c:\\hudson\\jobs\\QA Build Job\\workspace\\tags
3. FTP configurations.
Performing a QA Build
If you want to perform a QA build using the above described mechanism, first you need to choose a specific Integration build to tag it and promote it to QA. On Hudson please click on a Job, click on any already Integration build, and click on “Tag this build” and the following screen should appear:
In the above screen we are tagging from trunk to the tag folder the code that is inside mainline into the folder RC0.144-20110403.
After the tagging, we can perform a QA build. For that please go to QA Job and click on “Build Now”, so the following screen appears:
Here you just need to type the tag name that you enter during the tagging process as “RC0.144-20110403” and click on “Build”.