CI builds tend to generate a *lot* of output. With CruiseControl that’s no problem in itself, but you’ll probably want to purge old build artifacts periodically to avoid maxing out on disc usage.
Here’s a python script for cleaning up your artifacts dir. Posted by Phill (apparently doesn’t like to share his last name). Just put it somewhere sensible and slot into crontab.
#! /usr/bin/env python
# ==== Variables ====
ARTIFACTS_DIR="/opt/cruisecontrol/artifacts/"
NUM_BUILDS_TO_KEEP=10
# ==== End Variables ====
import os
def rm_recursive(path):
"""Removes a directory recursively"""
for root, dirs, files in os.walk(path, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))
#os.rmdir(path)
def delete_old_builds(path):
"""Deletes old builds"""
builds = os.listdir(path)
if len(builds) <= NUM_BUILDS_TO_KEEP:
print "No builds to delete"
return
builds.sort()
builds.reverse()
i = 0
for build in builds:
i += 1
if i <= NUM_BUILDS_TO_KEEP:
continue
print "Deleting", build
rm_recursive(os.path.join(path, build))
for file in os.listdir(ARTIFACTS_DIR):
path = os.path.join(ARTIFACTS_DIR, file)
if (os.path.isdir(path)):
delete_old_builds(path)
