In the interim between now and the last time we talked about this - I've learned quite a bit about NANT scripting. In the first place, it's best to put together a Cruise Control environment together APART from the one the app dev team is working with. People tend not to have a sense of humor about having their build tool go down in the middle of the day.
For This Project - You Will Need
Installing Cruise Control on your box is complex, but not terribly hard. In my case, my personal workstation is running XP Pro - I had to install IIS and .Net on the box using Microsoft's Add Windows services program and
the .Net 2.0 installer from their website. UseThoughtworks manual page for details on how to do it the right way. Once you get Cruise Control running - you can start messing with your ccnet.config file that controls kicking off different projects, including NANT. I didn't have to modify any CCNet file BESIDES this one - so keep that in mind if you get the urge to tinker.
Here follows a sample CCNet project that kicks off one build file from NANT. Notes and commentary after the sample:
<cruisecontrol>
<projectname="NANT-Activebranch01-DeployAll">
<tasks>
<nant>
<executable>C:\nant-0.85\bin\nant.exe</executable>
<buildFile>[Location of NANT .build file]</buildFile>
</nant>
<email from="[CCNet SMTP Address]" mailhost="xxx.xxx.xxx.xxx"->
mailhostUsername="ccnet.usrname" mailhostPassword="xxxx" includeDetails="TRUE">
<users>
<user name="User.A" group="buildmaster" address="user.a@domain.com"/>
<user name="User.B" group="developers" address="user.b@domain.com"/>
</users>
<groups>
<group name="developers" notification="change"/>
<group name="buildmaster" notification="always"/>
</groups>
</email>
</tasks>
</project>
</cruisecontrol>
Notes & Commentary
1. Make sure that your path to NANT is correct; Cruise Control will not be able to get to it otherwise.
2. NANT runs a .build file which is written in XML - the <NANT> task is simply telling NANT to run with that
.build file, wherever it is. Info about what the .build file will do to follow.
3. <EMAIL> will notify me or anyone else I designate when the NANT task is complete. I have to put in the address of our mail server, a username and a password to make it work (I also have to make sure my mail server
will accept this kind of traffic...). With that in place, we start experimenting with NANT commands to see
who does what, when and why. Fortunately, NANTBuilder is helpful with suggestions and sanity checkers to warn if you're missing a quotation mark or forward slash. It can only help so much, however, and this is why the NANT
reference manual is so helpful.
So I've created my Cruise Control, I'm ready to use NANT with it - let's look at a NANT deployment task - Notes and commentary follow:
<projectname="Project.Name" default="all">
<target name="all">
<servicecontroller action="Stop"service="W3SVC"machine="QA.Machine"/>
<property name="source" value="[sourcedirectory - \\machine.name\e$\...]"/>
<property name="web" value="[destinationdirectory - \\machine.name\e$\...]"/>
<delete dir="${web}\Project.Folder" failonerror="true"/>
<mkdir dir="${web}\Project.Folder" failonerror="true"/>
<copy todir="${web}\Project.Folder" failonerror="true">
<fileset basedir="${source}\Rest\of\Directory\Structure" failonempty="true">
<include name="**"/>
</fileset>
<filterchain>
<replacestring from="Old.String" to="New.String" ignorecase="true"/>
</filterchain>
</copy>
</target>
</project>
More Notes & Commentary
1. Note that you can end a NANT line without having to do the <command></command> syntax - just throw a/> at the end of the first line.
2. We're using the <servicecontroller> command to stop web services on the QA Machine. This is helpful to
prevent anyone from blundering into the deployment - testers might accidentally log on and then Windows will refuse to overwrite anything, citing 'files in use'. Get around this by killing the services.
3. We remove the destination project folder and then recreate it - although we used Robocopy previously, we wanted to make sure that all app files were completely removed from the old version. This has killed some weird issues we were experiencing between old build files and new build files.
4. The COPY and MOVE commands in NANT (see NANT reference for info about MOVE) have their own behaviors. MOVE does not run as quickly as a DOS move command. This became relevant later on. The copy command asks you to reference where everything will go first, then asks you to specify where it comes from and how
much of it ("**" means take everything). Additionally, the <filterchain> command allowed us to filter some character strings inside the files - this is helpful since we deploy to a number of places and have to filter our own web.config file every time to point to a settings folder.
It took a bit of experimentation to port our deployment builds over from DOS to NANT. You'll need to do the same - just spend time with all of the tools open, refer to the reference often and experiment, experiment, EXPERIMENT! I'm really jazzed now that it's cranking and I'm looking forward to making Selenium work with Cruise Control as well.
8.2.08
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment