Skip to content

Instantly share code, notes, and snippets.

@look4regev
Last active March 21, 2022 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save look4regev/0dbb1cd940ec44a4964dc68ad30d372b to your computer and use it in GitHub Desktop.
Save look4regev/0dbb1cd940ec44a4964dc68ad30d372b to your computer and use it in GitHub Desktop.
Delete jenkins jobs directories with a lot of old builds
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