27 October 2012

ccnet config in source control

Two posts ago I had a comment from Ignace in which he suggests the idea of having the configuration file of ccnet in the cvs (perforce in his and my case, but the idea applies to other systems as well). This is indeed a brilliant idea, because if you do that, the state of the code on the cvs will match the state of the config file (or build script, what it actually is). This is something you really need because more often than not the code and the way you build it are thightly coupled. It made me put on the thinking cap.

You cannot put the config file next to the code base, because
  • There are multiple projects in one config file, so in what project would you include it then?
  • There are multiple branches of a project, so what branch should define the build process for all other branches? What with merging branches then?

Another problem is that the server who uses the build script is a server. It cannot open up p4v and get the latest version. So if this needs to be done manually you can just as well just edit the script on the server an be done with it. The only reason to have the script on the cvs would be for logging purposes and backtracking. Not a good motivator, people would easily forget to update the script on the cvs, thus having the config out of sync which defeats the whole purpose then.

Googling a bit on this topic brought me to this post, which is actually the perfect solution for above issues. The config in the post did not work, at least not on the 1.8.2 server and with perforce, so here is my version:

<project name="Config File Monitor">
    <workingDirectory>%depot-root%\BuildServers\ServerName\</workingDirectory>
    <triggers>
        <intervalTrigger seconds="60"/>
    </triggers>
    <sourcecontrol type="p4">
        <view>//depot/BuildServers/ServerName/ccnet.config</view>
        ... and the other params you need ...
    </sourcecontrol>
    <tasks>
        <nullTask />
    </tasks>
    <publishers>
        <xmllogger />
    </publishers>
</project>

Add this project to your config file, place the file at the location specified in it (use a separate folder for each server) and change the path in the ccservice.config file. The project will check every minute if there is a new version of the config file and update it if needed. Since the server is monitoring that file it will automatically reload the configuration. I have not noticed any performance issues on the server of checking perforce every minute. Also note, I really needed to add the nulltask, otherwise it wouldn't work - no idea why, never bothered to check why.

I wanted to test this out for a while before posting about it, but now I know I'm very happy with this solution. We don't have to give special access anymore to some path on the server for users to be able to change the build config, they can just use perforce. The versions are in sync with the builds, and since you need to add a new project for every new branch it's good that the config file resides in its own folder - no messing with branches or anything. People can now also always review how a build is made themselves and don't have to ask the person responsible for the build server how the the build is made. A fine idea by Ignace and a fine solution I've found.

Have fun with this!

1 comment:

Calvin said...

This is a great postt thanks