So Java is good for something other than an abstract white coffee cup on an orange background in my system tray after all!
I am working with a friend on an attempt at best practices MVC development using the whole nine yards (DI, TDD, CI, git, SVN). I had sort of dreaded the part where I had to setup CruiseControl.NET because, well, I hate editing XML files and I hate configuring CC.NET. Then I stumbled across Chris Allport's blog post on Hudson for .NET Projects. Hudson is a continuous integration server written in Java and its trivially easy to install, setup, and get running. On my workstation it took less than 15 minutes to have a working build. My Windows Home Server (Windows Server 2003) it was a bit more taxing as I had no build environment so I'll detail the steps shortly.
Some of the advantages I see from Hudson, other than very easy to setup and configure:
- not a lot of hand editing XML files (you could I suppose)
- plugins - loads and loads - install from the web UI, no manual steps necessary
- has built in "install as Windows service" option
- if you do this, do it first for optimal user experience - if you set your hudson directory to something like "c:\hudson" and install as a Windows Service your previous settings will appear to be lost (but they aren't, they are just under the ~\.hudson folder Hudson uses by default)
- easy to manage security or for the masochistic LDAP integrated security
- very clean, responsive UI
- build reports, trends, status
- RSS feeds for build statuses per project plus email notification
- integrated textual help on just about everything
Its rare to find a software package that just feels enjoyable to use. Hudson is one of those software packages. It absolutely has displaced CC.NET for CI for me.
So on my bare Windows Server 2003 I had to install the following things (download links may not work due to session identifiers but you should be able to find everything after a cursory search):
- Java Runtime Environment 1.6 (1.5+ is required) [download]
- .NET Framework 3.5 with SP1 [download] (required a reboot)
- Hudson (latest stable) [download - can go out of date, look for the latest on the Hudson releases page]
- I placed the hudson.war file in c:\hudson and gave the local system (Network Service) account privileges to this folder
- Ruby (for Rake, optional if you use NAnt or something else) [download - this link can easily go out of date, you'll want the latest version of Ruby as always]
- after installation, Command Prompt and cd c:\ruby then gem install rake
- Windows SDK for Windows Server 2008 and .NET Framework 3.5 [download]
- Supported platforms: Windows Server 2003, amongst many others - don't let the name fool you!
- There is an ISO version and web installer - I went for the web installer and paired down the installed components to just the .NET SDK stuff
- (Optional) ASP.NET MVC if you are compiling an MVC application [download]
- (Optional) Visual Studio for C# Express [home page]
I also had to copy my workstation's MS Build targets (found, on Vista 64 by default at: C:\Program Files (x86)\MSBuild\Microsoft and ended up on my Windows 2003 Server 32-bit at Program Files\MSBuild\Microsoft [download]
After you're all setup, you can start Hudson by running:
java -jar c:\hudson\hudson.war*
then you can browse to http://localhost:8080 and begin your configuration - but if you're going to install Hudson as a Windows Service make sure to turn that on first so you don't waste time double configuring! Installing as a service was very easy but I did have to go to Computer Management > Services and manually restart Hudson due to a Java NullPointerException caused when the web UI tried to launch the service manually. No big deal.
I installed the Rake plugin and the NUnit plugin. Once doing this I restarted the service (there is a button after plugin installation to do this, and restarting the service from the service hosted HTTP server works fine).
After fiddling around with some settings (specifically email - I created a gmail account and used smtp.gmail.com over SSL for my build server) I moved onto configuring a job. Some settings I made for my build were:
- Advanced Project Options > Use custom workspace - I created c:\hudson\workspaces\specialorder and choose that as my custom workspace. Be foreward: this ended up causing my repository to be placed under c:\hudson\workspaces\specialorder\specialorder since I also set the Source Code Management > Local module directory (optional) value to "specialorder"
- For building I used rake because, well, its ridiculously easy. I used the example Rakefile.rb found on Chris Allport's blog "Getting Started with Rake on .NET Projects" as my basis, the resulting Rakefile.rb was placed in my source control repository's trunk\ directory and checked in.
task :default => :build task :build => [:clean, :compile, :test] task :clean do FileUtils.rm_rf("build")
# this doesn't do anything for me yet - have to conf. projects to ".." end task :compile do params = '/t:Rebuild /nologo /v:m /p:Configuration="Debug" src\SiameseHead.SpecialOrder.sln' msbuid = 'C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\MSBuild.exe' sh "#{msbuid} #{params}" end task :test do # FileUtils.cd 'build\\Debug' # exec "..\\..\\tools\\nunit\\nunit-console.exe TestStuffInDotNet.dll" end
You can see I haven't tried setting up automatic unit testing yet, but I will shortly.
- For Build > Advanced I specified the full path to the Rakefile.rb (C:\hudson\workspaces\specialorder\specialorder\trunk\Rakefile.rb) and the full path for the Rake working directory (C:\hudson\workspaces\specialorder\specialorder\trunk\); I was getting "invalid path" errors from Rake otherwise
Once you've saved your job you should be able to build it using the "Build Now" link and work your way through any errors (just click on failed builds then look for the "Console Output" link on the left side of the page).