In Less than Ten Minutes!
This article is all about how you can easily get up and running with CI in less than 10 minutes!
There are really two separate parts to gettings started with CI (and therefore two parts to this article).
- Setting up the build server and
- Creating the build (e.g. Nant files)
Then there are the issues you will face and need to find some form of resolution for.
First you need to download and install these tools:-
And Add the path to these exe files in your Environmental Variables
- msbuild (something like ‘C:\Windows\Microsoft.NET\Framework\v3.5’)
These are demo notes from a ‘lightning talk’ I gave at the Sydney Alt.Net user group in February.
In the talk I had only 10 minutes, so I made the presumption that all in attendance knew what CI was, if you don’t then check out these links, they will get you started:-
The Build Server
I’ve always used Cruise Control as it has always met my needs, is free, simple to get up and runnning and pretty much trouble free. For the demo I used version 1.4.2, when you download it, make sure you also get CCTray.
There are a number of other build servers out there that are definately worth looking at and comparing, I’m especially keen to try out Jetbrain TeamCity…when I find some time. It doesn’t matter which one you choose.
- Install Cruise Control (keep all of the default settings)
- Install CCTray (start it)
- Ok so now open CCTray settings and add (try to) a new build server.
Connect directly using .Net Remoting is the default, change it to Via the CruiseControl.NET dashboard (just a recommendation).
Click OK and you should see at the bottom a message saying, ‘Failed to connnect to server….’. We going to fix that right now.
Configure The Server
First thing we need to do is configure the service.
- Go here [C:\Program Files\CruiseControl.NET\server] or wherever you chose to install it.
- Open ccnet.config
- This is where things get personal. The example below is a basic configuration to point to an SVN Repository. The documentation on the Cruise Control website is concise and easy to follow so if your needs are different you’ll have no problems figuring out what you need to do.
- Add a ‘Project’ with the follow config sections:
- Source Control
- Build Task
- Save and double click on ccnet.exe
- You now have a working automated build! (well sort of…we still need to do the second part of the process, THE BUILD!)
TIP: Don’t forget to change the verbosity of the output to INFO (it’s currently DEBUG). Don’t worry CC will remind you every time it starts and tell you where the config file is that you need to change.
This is the contents of the config used in the demo, change it to suit your environment and save. Make sure:-
- The path to NAnt.exe is correct.
- The trunkURL for your repository is correct (or replace with appropriate section for your repository)
- Working directory and publish from directories are the same.
- You may need to make sure the SuccessfulBuilds directory exists before running…
Create the Build Files
The other big piece of the puzzle is the master.build file and the associated myProject.build files.
My tool of choice here is NAnt and I use (wrote) this generator to automatically create my build files and the master.build.
To create these use NantGenie (be sure to read the Notes section)…or you can write them from scratch.
That’s it you should be good to go. Start ccnet, checkin a change to your source, the build should start and run your new master.build file!
Ok so here’s where I have to come clean. It may have been a little white lie when I said that you could get CI up and running in less than 10 minutes. You are going to run into some other issues that is going to make it take….longer.
I discuss some of these issues in this article. But in a nutshell these will be the biggest thorns in your side:-
1. Database changes
Ideally when you check your code in, you are checking in a ‘unit of work’. This could include some app code changes AND some database changes, e.g. a new column and some data. Your tests rely on the database being up to date, so how do you ensure that the database on the build server DOES get updated when you checkin?
I’ve created an automated Db updater and put it on codeplex, it works for me. Check it out and I recommend looking at what other alternatives might work in your unique environment.
2. App.Config changes
So what is the best way to ‘manage’ the app.config files?
I don’t have a definitive answer for this one but I think that the following conditions are ‘desirable’ when planning how to manage your app.config.
- Like other code, you don’t want to have duplicates (including cross project).
- You only want data in there that is relevant to the project.
- Must be under source control.
- You want to be able to define what the variable contents should be in one place only. (where doesn’t matter too much as long as it is only one place)
- When you make changes to your App.Config, you want to make them whilst you are working on your relevant code change and then forget about it once it has been checked in. By ‘forget about it’ I mean you don’t have to remember to update the file on the UAT box when promoting a new build there and then remember to do the same change to Production…
All of this is tricky with an automated build and multiple environments.
Probably your biggest hurdle will be convincing people that CI helps and that they need to CHANGE their habits a little (sometimes alot) in order to make it work.
- If you’re struggling to figure out why the damn build is broken, the best place to look is here [C:\Program Files\CruiseControl.NET\server\YourProject\Artifacts\log].
- Also, don’t forget you can also turn the verbosity of the CC server back to DEBUG.
Hopefully this article will help reduce the time it takes to get some CI action happening in your team. Yes it is going to take more than 10 minutes but I guarantee you it is worth the effort and once you start using an automated build you simply refuse to go back to the chaos that preceded it!