TExcelTAD

Retention & Cleanup Policies

Every CI build that uploads artifacts adds gigabytes. A busy C++ project with debug symbols, several platforms and builds on every branch can add terabytes a month to its development repository. Without cleanup, storage costs grow forever and the repository manager slows down. With careless cleanup, you delete the one build a customer is running and lose the debug symbols you need for their crash dump.

A retention policy states, per repository, what may be deleted and when.

Typical rules

Repository Keep Delete
dev / snapshots the last N builds per branch; anything downloaded in the last D days builds of merged or deleted branches after a grace period; everything older than D days not in the "last N"
staging / candidates candidates of the last few release cycles rejected candidates after a few weeks
release everything that was ever shipped (or per support policy) nothing automatically; manual, audited deletion of end-of-life versions
proxy caches the working set (proxy model) artifacts not downloaded for months (they can be fetched again from upstream)
debug symbols as long as the matching release is supported together with the release

The tools: Artifactory has cleanup policies (retention by age, last-downloaded date, number of versions, properties) and the AQL query language for custom scripts; Nexus has cleanup policies (component age, last downloaded, release/pre-release, regex) run by a compact-blob-store task; GitHub Packages and container registries have retention settings and APIs; Maven snapshot repositories can keep only the last N timestamped snapshots.

A model of a cleanup run

The model applies a typical dev-repository policy to an inventory of 30 builds and prints what it deletes and why. Every decision has a reason that would go into an audit log:

python · try it yourself
from dataclasses import dataclass

@dataclass
class Build:
    branch: str
    number: int
    age_days: int
    last_download_days: int
    size_gb: float
    released: bool = False

TODAY_BRANCHES = {"main", "release/1.4", "feature/net"}       # still exist
inventory = []
for i in range(12):
    inventory.append(Build("main", 100 + i, age_days=60 - 5 * i, last_download_days=40 - 3 * i, size_gb=2.0,
                           released=(100 + i) in (103, 108)))
for i in range(8):
    inventory.append(Build("release/1.4", 200 + i, age_days=45 - 5 * i, last_download_days=30 - 4 * i, size_gb=2.2))
for i in range(5):
    inventory.append(Build("feature/net", 300 + i, age_days=10 - 2 * i, last_download_days=10 - 2 * i, size_gb=1.5))
for i in range(5):
    inventory.append(Build("feature/old-ui", 400 + i, age_days=90 - i, last_download_days=80 - i, size_gb=1.5))
inventory[13].last_download_days = 2          # someone is bisecting with release/1.4 build 201

KEEP_LAST, MAX_AGE, RECENT_DOWNLOAD = 3, 30, 7

def decide(b, newest_numbers):
    if b.released:
        return "keep", "shipped (promoted to release)"
    if b.branch not in TODAY_BRANCHES:
        return "delete", "branch deleted"
    if b.number in newest_numbers[b.branch]:
        return "keep", f"one of the last {KEEP_LAST} on {b.branch}"
    if b.last_download_days <= RECENT_DOWNLOAD:
        return "keep", "downloaded in the last week"
    if b.age_days > MAX_AGE:
        return "delete", f"older than {MAX_AGE} days"
    return "keep", "young enough"

newest = {}
for b in sorted(inventory, key=lambda b: -b.number):
    newest.setdefault(b.branch, [])
    if len(newest[b.branch]) < KEEP_LAST:
        newest[b.branch].append(b.number)

freed, reasons = 0.0, {}
for b in inventory:
    action, why = decide(b, newest)
    reasons[(action, why)] = reasons.get((action, why), 0) + 1
    if action == "delete":
        freed += b.size_gb
total = sum(b.size_gb for b in inventory)
for (action, why), n in sorted(reasons.items()):
    print(f"{action:<6} {n:>2} builds: {why}")
print(f"freed {freed:.1f} GB of {total:.1f} GB ({freed / total:.0%})")
delete  5 builds: branch deleted
delete  7 builds: older than 30 days
keep    1 builds: downloaded in the last week
keep    3 builds: one of the last 3 on feature/net
keep    3 builds: one of the last 3 on main
keep    3 builds: one of the last 3 on release/1.4
keep    2 builds: shipped (promoted to release)
keep    6 builds: young enough
freed 21.9 GB of 56.6 GB (39%)

The two released builds of main survive although they are old: being shipped trumps every age rule. The whole feature/old-ui branch goes because the branch no longer exists. And build 201 of release/1.4 is 40 days old and not among the last three, yet it stays because someone downloaded it two days ago (a tester, a bisect, a customer): deleting artifacts that are in use is how cleanup jobs make enemies.

Rules that save you from bad days

  • Mark, don't infer. "Released" should be a property set at promotion time (or a separate release repository), not guessed from version strings.
  • Dry-run first, always. Run the policy in report mode, review the list, then delete. Artifactory and Nexus both support previews; scripts should default to --dry-run.
  • Keep debug symbols as long as their binaries. A crash dump from a supported release without symbols is a bad day. Symbol servers need their own retention, tied to releases.
  • Deletion isn't instant reclamation. Repository managers deduplicate by checksum: the same blob may be referenced by several repositories, and space is reclaimed by a separate garbage-collection or compaction task.
  • Logs and auditability. Record what was deleted, by which rule, and when: "why is build 812 gone?" will be asked.

Test yourself

Which rule should win over all age-based rules in a dev repository?

  1. Branch deleted
  2. The build was shipped/promoted
  3. Older than 30 days
  4. Biggest file first

Why keep builds that were downloaded in the last week, even if they're old?

  1. They are smaller
  2. Someone is using them (testing, bisecting, a customer)
  3. Repository managers require it
  4. They are releases

You deleted 2 TB of artifacts but the disk usage barely moved. Likely reason?

  1. The deletion failed
  2. Blobs are deduplicated and space is reclaimed later by a garbage-collection/compaction task
  3. Deleted files are kept forever
  4. The disk is read-only