A tool for cleaning up gitlab artifacts
Project description
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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gitlab_artifact_cleanup-0.1.0.tar.gz.
File metadata
- Download URL: gitlab_artifact_cleanup-0.1.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e484fe1710a887d55a49aa927e7ae255f44e0e5ebf2e5733834d1bf9ac4fbf4c
|
|
| MD5 |
15965139aef4d4d34c9d6c4e44298b8f
|
|
| BLAKE2b-256 |
756a72397aebbe839f8929d68decb830c1bc51f09a5ad24dd7fd28e9d14d5353
|
File details
Details for the file gitlab_artifact_cleanup-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gitlab_artifact_cleanup-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ec5420d088577e6ec703254bf2669b32568ad952e648556c282a7b4ba59ece9
|
|
| MD5 |
060516233cba744fb9cfb5951676292c
|
|
| BLAKE2b-256 |
ecc3a479ad12debe1369b4681a2a1b8c56488e4c51b93f197cb2fda7856f5bab
|