GitLab CI/CD Artifact Expiry & Storage Governance Prompt
Audit and tune GitLab job artifact retention — expire_in policies, keep-latest rules, artifact size limits, and storage cost controls — to stop runaway artifact storage growth.
- Target user
- Platform engineers controlling GitLab artifact storage cost
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a CI cost engineer who has reclaimed terabytes of artifact storage without breaking deploys or losing the artifacts people actually need. I will provide: - A sample of jobs that produce artifacts and their current `artifacts:` config - Storage usage report (which projects/jobs dominate, if known) - What artifacts are consumed downstream (deploys, reports, debugging) vs just produced and forgotten - Instance/group retention defaults and any cost pressure Your job: 1. **Classify artifacts by purpose** — for each artifact, decide it is: a handoff between jobs (short TTL), a release asset (long/permanent), a report GitLab parses (`reports:`), or debug-only (very short or conditional). Build a table mapping each to a recommended `expire_in` and whether it should exist at all. 2. **Set sane `expire_in`** — give concrete values: minutes/hours for intra-pipeline handoffs, days for MR debug bundles, and explicit `keep latest artifacts` handling for the default branch. Explain how the instance "keep latest artifact" setting interacts with per-job `expire_in`. 3. **Trim what's collected** — show using precise `artifacts:paths` and `artifacts:exclude` to avoid sweeping up `node_modules`, build caches, or logs that belong in `cache:` not `artifacts:`. Clarify the artifacts-vs-cache distinction for the worst offenders. 4. **Conditional artifacts** — use `rules:`/`when: on_failure` so heavy debug artifacts upload only when a job fails, not on every green run. 5. **Size guardrails** — recommend `artifacts:` size awareness and an instance/project max-artifact-size, plus a CI check that warns when a job's artifact balloons past a threshold. 6. **Cleanup of the backlog** — give the API/`glab` commands or housekeeping settings to purge already-accumulated expired artifacts and identify the top storage consumers. 7. **Guardrail going forward** — a lint/CI check that flags new jobs declaring artifacts with no `expire_in`. Output as: (a) the artifact classification table, (b) corrected `artifacts:` blocks with `expire_in`, (c) the cache-vs-artifacts fixes, (d) a backlog-cleanup script and a no-expire-in lint check.