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)
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"