Jenkins/misc/clean-worker.sh

26 lines
527 B
Bash

#!/bin/sh
cleanup_docker() {
RUNNING_CONTAINERS=$(docker ps -q)
if [ ! -z "$RUNNING_CONTAINERS" ]; then
docker stop $RUNNING_CONTAINERS
fi
docker system prune -f -a --volumes
docker network prune -f
service docker restart
}
cleanup_old_workspaces() {
# Suppression des workspaces dont la dernière date
# de modification est supérieure à 7 jours.
find /workspace -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \;
}
main() {
cleanup_docker
cleanup_old_workspaces
}
main