diff --git a/scripts/jenkins_cleanup.sh b/scripts/jenkins_cleanup.sh new file mode 100644 index 0000000..1a783af --- /dev/null +++ b/scripts/jenkins_cleanup.sh @@ -0,0 +1,34 @@ +#/!/bin/bash + +# Script run on the Jenkins Node after the build(tests) are completed. +# Forcibly cleans up _ALL_ VirtualBox VMs, not just those created during +# the Jenkins run. + +# Doing each command with "|| true" so that even if a command fails, it won't +# cause Jenkins to mark the build as failed. + +set -e + +echo "Starting cleanup." +echo "Existing VMs:" +vboxmanage list vms +echo "------------" + +cd $WORKSPACE/src/github.com/contiv/netplugin +vagrant destroy -f || true + +rm -rf /home/admin/VirtualBox\ VMs/* || true +rm -rf .vagrant/* || true +rm -f *.vdi || true + +for f in $(vboxmanage list vms | awk {'print $2'} | cut -d'{' -f2 | cut -d'}' -f1); do + echo $f + vboxmanage controlvm $f poweroff || true + sleep 5 + vboxmanage unregistervm --delete $f || true +done + +echo "Cleanup finished." +echo "any VMs still left?" +vboxmanage list vms +echo "------------"