Skip to content

Instantly share code, notes, and snippets.

@vStone
Created October 4, 2013 10:25
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 vStone/6823921 to your computer and use it in GitHub Desktop.
Save vStone/6823921 to your computer and use it in GitHub Desktop.
Cleanup old jenkins (plugin) packages
green='\033[0;32m'; red='\033[0;31m';
reset='\033[0m';
## Keep the haltest # number of versions for each plugin.
KEEP_PLUGINS=2
echo "Begin processing..."
count=$( ls *.rpm | grep -o "jenkins-plugin-[a-z]\+[0-9a-z-]*[0-9a-z]\+-" | sort | uniq | wc -l )
i=0
while read plugin; do
let i++
echo "[ $i/$count ] $plugin"
versions=$( ls ${plugin}[0-9]*.rpm | wc -l )
if [ $versions -gt $KEEP_PLUGINS ]; then
echo "Plugin: $plugin (Count: $versions)";
remove=( ` ls ${plugin}[0-9]*.rpm | sort -g -t"." -k2,3 | head -n -2 ` )
keep=( ` ls ${plugin}[0-9]*.rpm | sort -g -t"." -k2,3 | tail -n 2 ` )
echo -e "+++ ${green}${keep[@]}${reset}"
echo -e "--- ${red}${remove[@]}${reset}"
rm "${remove[@]}"
fi;
done < <( ls *.rpm | grep -o "jenkins-plugin-[a-z]\+[0-9a-z-]*[0-9a-z]\+-" | sort | uniq )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment