Earlier I posted that I had used the following zip command in the ‘execute shell’ action for my Hudson build job:
zip -r $WORKSPACE/builds/$JOB_NAME-$BUILD_NUMBER * -x ‘*/.svn/*’ -x ‘*builds/*’
This zips up the content of the exported source, so that I can send it on to team members who need the source of each build but aren’t authorized for the source control system.
That has been working splendidly except that I have some resource issues on the server I’m using for these builds, so I’m occasionally running out of space. I really only need to keep the latest successful build’s zip file, so after a bit of trial and error, I came up with this script for finding older builds and deleting them:
oldbuild=$(($BUILD_NUMBER – 3))
find . -type f -name “*-$oldbuild.zip” -exec rm -f {} \;
This is using the $BUILD_NUMBER built-in environment variable from Hudson to set a variable named oldbuild to a zip from 3 builds ago, and then finding that file (since I had named the file $JOB_NAME-$BUILD_NUMBER in the zip command) and removing it.
So now Hudson is creating the builds and cleaning up after itself! Hmmm, if only I could get the kitchen to do that for dinner.