Skip to main content

GitLab Artifact Cleanup

Overview

gitlab-artifact-cleanup is a tool to clean up old artifacts from GitLab CI/CD jobs.

Motivation

GitLab has a built-in feature to delete artifacts from jobs that are older than a given threshold. However, there are cases when this auto-cleanup does not apply:

  • If auto-cleanup was disabled before, all artifacts that were created before auto-cleanup activation won't be deleted.
  • Job artifacts which belong to the latest commit of a branch or to a tag are not deleted.
  • If project pipelines keep failing constantly, all artifacts of the last successful pipeline will be kept.
  • Artifacts that are selected to be kept manually (with the web UI for example) will be kept forever.

In these cases, artifacts can only be deleted manually in the web UI or with the GitLab API. gitlab-artifact-cleanup uses the GitLab API and provides a convenient command line tool and a simple Python high-level API to clean up old artifacts.

Installation

From PyPI

gitlab-artifact-cleanup is available as a Python package on PyPI. Install it using pip or pipx:

python3 -m pip install gitlab-artifact-cleanup

or

pipx install gitlab-artifact-cleanup

The tool requires at least Python 3.9.

AUR

For Arch and its derivates, gitlab-artifact-cleanup is also available in the AUR and can be installed with any AUR helper, for example yay:

yay -S gitlab-artifact-cleanup

Usage

Command line tool

Run

gitlab-artifact-cleanup --write-default-config

to create an initial configuration file at ~/.gitlab-artifact-cleanuprc. Then, open the web page of your GitLab instance and navigate to User Settings -> Access Tokens. Create a new token with the api scope and copy its contents into the newly created configuration file (access_token) and set the url of your GitLab server if you are not using gitlab.com.

Now, run

gitlab-artifact-cleanup --dry-run [project_name]

to scan a given project for artifacts to be deleted. With --dry-run the tool only creates a list of artifacts that would be deleted but does not apply any changes to the GitLab project. By default, all artifacts older than 7 days will be erased that are not associated to any branch or tag. These default values can be adjusted on the command line or in the configuration file (run with --help to get list of all options and their possible values).

Omit --dry-run to apply the changes and delete the artifacts.

Python API

You can import a Gitlab class from the gitlab_artifact_cleanup package to clean up artifacts from a Python script. This is a simple example:

#!/usr/bin/env python3

from gitlab_artifact_cleanup import Gitlab


def main():
    gitlab = Gitlab(
        "https://gitlab.com",
        "my-very-secret-access-token",
        dry_run=True,
    )
    gitlab.delete_old_artifacts(
        "username/myproject",
        days_to_keep=14,
        keep_artifacts_of_latest_branch_commit=True,
        keep_artifacts_of_tags=True,
        delete_logs=False,
    )


if __name__ == "__main__":
    main()

Metadata

Release files for gitlab-artifact-cleanup 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gitlab-artifact-cleanup 0.1.0
File Size Uploaded Provenance Actions
gitlab_artifact_cleanup-0.1.0.tar.gz 12.7 kB Without provenance Details for gitlab_artifact_cleanup-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gitlab-artifact-cleanup 0.1.0
File Interpreter ABI Platform Actions
gitlab_artifact_cleanup-0.1.0-py3-none-any.whl Python 3 none any Details for gitlab_artifact_cleanup-0.1.0-py3-none-any.whl

Total release size: 25.7 kB

Release files / gitlab_artifact_cleanup-0.1.0.tar.gz

Download URL gitlab_artifact_cleanup-0.1.0.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e484fe1710a887d55a49aa927e7ae255f44e0e5ebf2e5733834d1bf9ac4fbf4c
BLAKE2b-256 checksum
How to use checksums
756a72397aebbe839f8929d68decb830c1bc51f09a5ad24dd7fd28e9d14d5353
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / gitlab_artifact_cleanup-0.1.0-py3-none-any.whl

Download URL gitlab_artifact_cleanup-0.1.0-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ec5420d088577e6ec703254bf2669b32568ad952e648556c282a7b4ba59ece9
BLAKE2b-256 checksum
How to use checksums
ecc3a479ad12debe1369b4681a2a1b8c56488e4c51b93f197cb2fda7856f5bab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for gitlab-artifact-cleanup 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page