Skip to content

Instantly share code, notes, and snippets.

@manisnesan
Created May 15, 2014 17:53
Show Gist options
  • Save manisnesan/d2d8c6b9e70193b89ef5 to your computer and use it in GitHub Desktop.
Save manisnesan/d2d8c6b9e70193b89ef5 to your computer and use it in GitHub Desktop.
Maven Housekeeping in Jenkins
#!/bin/bash
#
# This script cleans up m2 repository SNAPSHOT jars that are older than specified $AGE days in Jenkins host.
#
#
M2_REPO=/usr/share/tomcat6/.m2
OLDFILES=/tmp/oldfiles.txt
AGE=21
echo "Starting M2 directory clean up "
find "${M2_REPO}" -name '*-SNAPSHOT*jar' -atime +${AGE} -exec dirname {} \; >> ${OLDFILES}
for x in `sort ${OLDFILES} | uniq`; do echo "Removing ${x}"; rm -rf "$x"; done
#Remove empty directories
find "${M2_REPO}" -type d -empty -exec rmdir {} \; >> ${OLDFILES}
rm ${OLDFILES}
echo "Done with M2 directory clean up"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment