From: Holger Levsen Date: Wed, 17 Oct 2012 09:10:06 +0000 (+0200) Subject: implement proper garbage collection, delete results if jenkins logs are deleted X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=504b86dfd24ac69b5c6a6b36c8020b0cc2500b93;p=profitbricks%2Fjenkins-build-scripts.git implement proper garbage collection, delete results if jenkins logs are deleted --- diff --git a/extract_storage_kernel+modules.sh b/extract_storage_kernel+modules.sh index 1b45d07..307c4c5 100755 --- a/extract_storage_kernel+modules.sh +++ b/extract_storage_kernel+modules.sh @@ -15,14 +15,16 @@ export PB_SUITE=$DISTRIBUTION export TARGET_BASE=/srv/storage-kernels if [ "$DISTRIBUTION" = "production-proposed-updates" ] ; then - export TARGET_DIR=$TARGET_BASE/master/$BUILD_NUMBER + export TARGET_NAME=master elif [ "$DISTRIBUTION" = "pre-staging" ] ; then - export TARGET_DIR=$TARGET_BASE/develop/$BUILD_NUMBER + export TARGET_NAME=develop else echo "DISTRIBUTION must be 'production-proposed-updates' or 'pre-staging', exiting." figlet "FAIL" exit 1 fi +export TARGET_DIR=$TARGET_BASE/$TARGET_NAME/$BUILD_NUMBER +export JOB_HOME=$JENKINS_HOME/jobs/$JOB_NAME/builds SCRIPTSDIR=$(dirname $0) BUILD_SCRIPT=$(mktemp) @@ -49,30 +51,20 @@ sudo pbuilder --execute --bindmounts $TARGET_BASE -- $BUILD_SCRIPT rm $BUILD_SCRIPT -# TODO: implement better garbage collection, allow to keep images +echo "Garbage collection in debug mode..." # -# cleanup $TARGET_DIR, keep MAX number of images +# cleanup $TARGET_DIR, keep as many images as jenkins # -MAX=15 -cd $TARGET_BASE -for t in master develop ; do - cd $t - COUNT=0 - for i in $(ls -atd1) ; do - if [ "$i" != "." ] ; then - let COUNT=COUNT+1 - if [ $COUNT -gt $MAX ] ; then - echo sudo rm -rfv ./$i - else - echo "keeping $i" - fi - fi - if [ $COUNT -gt 0 ] ; then - figlet "Warning:" - echo "Garbage collection disabled." - fi - done - cd .. +cd $TARGET_BASE/$TARGET_NAME +# loop through all results of current target +for i in $(ls -atd1) ; do + echo $i + # check if the jenkins build log still exists, if not, delete the old target as well + if [ "$i" != "." ] && [ ! -L $JOB_HOME/$i ] ; then + echo sudo rm -rfv ./$i + else + echo "keeping $i" + fi done figlet "OK"