Tuesday, July 13, 2004

General ANT build and release scripts

While pottering about with SVN and ANT, I discovered - yes, you guessed it - SVNANT, a plug in custom task for ANT which provides integration with SVN repositories.

So, I had a bit of a play, and came up with two ANT scripts that I thought I'd share, to save other innocents the buttock-clenching frustration that ANT development on Windows can be.

The first script is to be run on your development machine, and it's called build.xml

This build script:

  • Connects to a given repository repository

  • Exports all files in a given revision from the given folder to a temporary directory

  • Zips up all files within that temporary folder which have been modified since a given date

  • Clears up the temporary folder


…producing a timestamped zip file containing all files changed since a given date.

You can then upload the zip file to the live server and extract it over the live code using the second script, release.xml.

This second script:

  • Scans the build/ directory for build_*.zip files

  • Asks you to choose the build file for release

  • Backs up all files contained in the zip file to the build/ directory

  • Extracts the build_*.zip over the top of the existing files


giving you a backup file called BACKUP_(whatever your build file was called).zip, which you can easily re-apply if something goes wrong with your release.

So, to run the build.xml file on your dev machine, you will need :

You can download all the above in one package here : build_release_files.zip

I'd recommend that you put the three files in the root of your project - most projects I've worked on tend to have a structure along the lines of:

Project Root
- wwwroot
- components (or custom tags, or whatever)

so i've written the scripts on the basis of them being in the project root.

One thing to note : you'll need to set the repoURL value in build.properties to the default url of your repository in SVN, something like svn://yourserver/yourrepository/trunk

To run the script, just open up a command prompt, cd to the project root directory, type:
ant


and follow the on-screen prompts.

This will produce a build file in the Project Root/build/ subdirectory, which will be created if necessary.

On your live server, you'll need a working installation of ANT, plus this file : release.xml

Again, put this in your project root directory on the live server.

To run it, again open a command prompt and cd to the project root directory, but this time type:
ant -f release.xml


to make ant execute the file release.xml (by default it looks for build.xml)

It will look for zip files in the Project Root/build/ subdirectory, so make sure your build .zip file is in there. Again, it prompts you for everything it needs.

Standard legal disclaimer bumph: these files are provided as is, use them at your own risk, if it makes a mess of your server, it's entirely your own fault and I'm not accepting any responsibility whatsoever. Nope, none. Sorry...

Happy scripting!

9 comments:

Anonymous said...

I could not download your samples.

Could you please pack the *.xml *.properties *.etc in a zip form?

Its taking hard time to downloads that file in raw form. The IE/Firefox wrongly interprets especially build.xml.

Alistair Davidson said...

Sure - try this zip package: build_release_files.zip

Anonymous said...

This is AWESOME!! I can't believe it hasn't gotten more attention.

Mike Henke said...

I added js / css minifying (YUI Compressor OR JSMin) and jslint to your great build script.

http://tinyurl.com/29684y

Alistair Davidson said...

Excellent! nice one mike

Mike said...

Here is my attempt @ an ant for revision by range instead of an export - http://tinyurl.com/4lmjoq

Ron said...

Thanks for the scripts! I am converting build scripts for ANT that use CVS commands to SVN - I was looking for a simpler method of employing SVN command line.

nolandubeau said...

Very cool! Thanks for sharing. Wondering if anyone has seen any modified versions of this which integrates with GIT instead of SVN? Thanks!

nolandubeau said...

Very cool! Thanks for sharing. Wondering if anyone has seen any modified versions of this which integrates with GIT instead of SVN? Thanks!