]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
implement proper garbage collection, delete results if jenkins logs are deleted
authorHolger Levsen <holger@layer-acht.org>
Wed, 17 Oct 2012 09:10:06 +0000 (11:10 +0200)
committerHolger Levsen <holger@layer-acht.org>
Wed, 17 Oct 2012 09:10:06 +0000 (11:10 +0200)
extract_storage_kernel+modules.sh

index 1b45d0762a3f7ed3eb5fa4d893c5797fb43aaced..307c4c5c0cf7247811002052eb9ca93285c8be56 100755 (executable)
@@ -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"