Last active
January 25, 2017 00:48
-
-
Save thinkmassive/7c8f4feafa1056d4c5538c08ac6eeac8 to your computer and use it in GitHub Desktop.
Remove projects in Jenkins workspace with no files modified within the past 90 days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
WORKSPACE_DIR=/var/lib/jenkins/workspace | |
DAYS_TO_KEEP=90 | |
DRY_RUN=1 | |
VERBOSE=1 | |
[ $DRY_RUN ] && echo "DRY RUN..." | |
for projectdir in `ls -d1 "$WORKSPACE_DIR"/*`; do | |
num_new_files=$(find "$projectdir" -mtime -$DAYS_TO_KEEP -not -path "$projectdir/.git/*" | wc -l) | |
if [ $num_new_files == "0" ]; then | |
if [ $DRY_RUN ]; then | |
echo "Would remove $projectdir" | |
else | |
[ $VERBOSE ] && echo "Removing $projectdir" | |
rm -rf "$projectdir" | |
fi | |
else | |
[ $VERBOSE ] && echo "Skipping $projectdir ($num_new_files files <$DAYS_TO_KEEP days)" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment