Last active
March 21, 2022 15:27
-
-
Save look4regev/0dbb1cd940ec44a4964dc68ad30d372b to your computer and use it in GitHub Desktop.
Delete jenkins jobs directories with a lot of old builds
This file contains 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
find ${JENKINS_HOME_PATH} -maxdepth 2 -type d -print0 -name "builds" | while read -d '' -r dir; do | |
files=("$dir"/*) | |
if [ "${#files[@]}" -gt 30 ]; then | |
if [[ "$dir" =~ .*"builds_"$ ]]; then | |
echo "removing $dir" | |
rm -rf $dir | |
else | |
printf "%5d files in directory %s\n" "${#files[@]}" "$dir" | |
rm -rf "${dir}_" | |
mv "${dir}" "${dir}_" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment