Nice solution for keeping Hudson configuration in SVN repository

Here is a nice and simple solution for keeping the Hudson configuration in SVN.

I believe it's much better than just backup it since in SVN (or another version control) you are able to see the history and quickly revert the changes.

See the full article here.

Comments

Hudson blog has been moved, so here is the link to the original post

 

I needed the same solution for Windows, and since I didn't succeed to convert it into windows batch script - simple commands become too complicated! :), I converted it to work with cygwin, and it works like magic..

Don't forget to add c:\cygwin\bin to your PATH and restart Hudson service.

Here is my script for cygwin with a few small changes from the script from the original post:

 

#!/bin/bash
export HUDSON_HOME="`cygpath c://.hudson`"
echo Hudson home is "$HUDSON_HOME"
# Change into your HUDSON_HOME.
cd "$HUDSON_HOME"
# Add any new conf files, jobs, users, and content.
svn add -q --parents *.xml jobs/*/config.xml jobs/*/nextBuildNumber users/*/config.xml userContent/* plugins/*

# Ignore things in the root we don't care about.
echo -e "war\nlog\n*.log\n*.tmp\n*.old\n*.bak\n*.jar\n*.json" > myignores
svn propset svn:ignore -F myignores . && rm myignores
# Ignore things in jobs/* we don't care about.
echo -e "builds\nlast*\nnext*\n*.txt\n*.log\nworkspace*\ncobertura\njavadoc\nhtmlreports\nncover\ndoclinks\nmodules" > myignores
svn propset svn:ignore -F myignores jobs/* && rm myignores

# Remove anything from SVN that no longer exists in Hudson.
svn status | grep '\!' | awk '{print $2;}' > delfiles
sed -i 's/\\/\//g' delfiles
cat delfiles | xargs -r svn rm && rm delfiles

# And finally, check in of course, showing status before and after for logging.
svn st && svn ci --non-interactive --username=builder --password=benny2000 --no-auth-cache -m "automated commit of Hudson configuration" && svn st

 

Thumbs up for the nice work.

Same thing to do but for CVS. Nice and easy.

The one of the different between SVN and CVS - add do not work recursively. So instead of do chain of find and grep -v (it's take time) I do tar with --exclude.

So:

1. Simple hudson job. Running @midnigth.

2.1 Script inside (this will add new tar each midnigth):

cd $HUDSON_HOME

tar -zcvf hudson_backup_${BUILD_ID}.tar.gz *.xml ./jobs/*/config.xml ./users/*/config.xml ./userContent/* --exclude '*/CVS/*' --exclude '*/CVS' --exclude './jobs/*/workspace/*' --exclude './jobs/config-history/*' --exclude '*.log'

cvs add hudson_backup_${BUILD_ID}.tar.gz
cvs ci -f -m "hudson backup ${BUILD_ID}" hudson_backup_${BUILD_ID}.tar.gz

rm hudson_backup_${BUILD_ID}.tar.gz

2.2 This will overwrite same tar each time.

TAR_NAME="hudson_backup.tar.gz"

cd $HUDSON_HOME

cvs co $HUDSON_HOME

tar -zcvf ${TAR_NAME} *.xml ./jobs/*/config.xml ./users/*/config.xml ./userContent/* --exclude '*/CVS/*' --exclude '*/CVS' --exclude './jobs/*/workspace/*' --exclude './jobs/config-history/*' --exclude '*.log'

cvs add ${TAR_NAME}
if [ ! -f "${TAR_NAME}" ]
then
cvs add ${TAR_NAME}
fi
cvs ci -f -m "hudson backup ${BUILD_ID}" ${TAR_NAME}

rm ${TAR_NAME}