Skip to content

Instantly share code, notes, and snippets.

@danvideo
Forked from jbasila/jenkins-delete-builds.groovy
Created September 16, 2019 12:00
Show Gist options
  • Save danvideo/000afaaf754be8f57f96935b118742d4 to your computer and use it in GitHub Desktop.
Save danvideo/000afaaf754be8f57f96935b118742d4 to your computer and use it in GitHub Desktop.
Jenkins: Delete older builds
// run this on the master:
// $ du -sk MAG-* |sort -rn|head -20 | while read _line ; do _ar=( ${_line} ); echo -n "\"$(cat ${_ar[1]}/name-utf8.txt)\", "; done ;echo ""
_array=[ ]
_array.each {
JOB_NAME="Magnifier/${it}"
KEEP_LAST_NUM_OF_BUILDS=2
Jenkins.instance.getItemByFullName("${JOB_NAME}").builds.findAll { true }.each {
if (KEEP_LAST_NUM_OF_BUILDS) {
KEEP_LAST_NUM_OF_BUILDS--
} else {
it.delete()
}
}
}
@danvideo
Copy link
Author

danvideo commented Dec 3, 2019

pushd /var/lib/docker/volumes/data/_data/jobs
# 1
find ./**/branches/**/builds -maxdepth 1 -xdev -type d -ctime +7 -exec du -sh {} ';' | sort -n -r | head -n 100 | awk '{print $2}' | xargs -i@@ rm -vr '@@' >> /var/log/jenkins-cleaner.log.manual
# 2.
find . -name *.log -mtime +3 | xargs -I@@ rm @@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment