Clean up storage
- Tier: Premium, Ultimate
- Offering: GitLab.com
- Status: Beta
Artifact Central keeps every artifact you publish and every entry a remote repository caches until you delete it. Everything a repository holds counts toward its stored size.
Storage cleanup removes what you no longer need:
- From a hosted repository, you delete artifacts, such as old package versions or images.
- From a remote repository, you evict cache entries that nobody downloads anymore. The next pull fetches an evicted entry from the upstream again.
A virtual repository stores no artifacts, so you clean up its upstream repositories instead.
In the UI, you can delete one artifact at a time or clear a remote repository’s whole cache. Bulk deletes, and eviction of only idle entries, are available in the management API.
Prerequisites
- The Artifact Manager or Artifact Admin role on the repository.
- An Artifact Central token. For more information, see authenticate with Artifact Central.
In the examples on this page, replace the following placeholders:
<registry_handle>: Enter your organization’s registry handle.<repository_name>: Enter the name of your repository.<format>: Enterdockerorocifor a container repository, ormavenornpmfor a package repository. The value must match the repository’s format.
The examples call the management API at https://artifact-registry.gitlab.com/api/v1/<registry_handle>/
and expect the token in AR_TOKEN.
Delete artifacts in a batch
A bulk delete takes up to 1,000 IDs or digests and returns 202 Accepted.
The registry applies the batch in the background, so read the list again to see the result.
An entry that is already gone is skipped, so you can send the same batch again.
For example, to delete two versions of a Maven or npm package:
curl --request POST \
--header "Authorization: Bearer $AR_TOKEN" \
--header "Content-Type: application/json" \
--data '{"version_ids": ["<version_id_1>", "<version_id_2>"]}' \
"https://artifact-registry.gitlab.com/api/v1/<registry_handle>/repositories/<repository_name>/<format>/packages/<package_id>/versions/bulk_delete"To find the IDs, list the collection first. For example, list a package’s versions with
GET .../<format>/packages/<package_id>/versions.
| To delete | Send POST to | Body |
|---|---|---|
| Images | .../<format>/images/bulk_delete | {"image_ids": [...]} |
| Tags of one image | .../<format>/images/<image_id>/tags/bulk_delete | {"tag_names": [...]} |
| Manifests of one image | .../<format>/images/<image_id>/manifests/bulk_delete | {"digests": [...]} |
| Packages | .../<format>/packages/bulk_delete | {"package_ids": [...]} |
| Versions of one package | .../<format>/packages/<package_id>/versions/bulk_delete | {"version_ids": [...]} |
| Files of one version | .../<format>/versions/<version_id>/files/bulk_delete | {"file_ids": [...]} |
To empty a collection, send {"delete_all": true} instead of a list.
Deleting a tag doesn’t lower the stored size, because the manifest it points to stays. Deleting a manifest lowers it only by the manifest itself, because the image’s layers stay.
Deleted artifacts cannot be restored. On a hosted repository, deleting an image or package also deletes everything under it.
To delete one artifact at a time, see delete an artifact.
Clear idle entries from a remote repository’s cache
A remote repository caches every image and package your builds pull through it. Entries that
nobody pulls anymore stay in the cache and count toward the repository’s stored size.
To find them, pass last_downloaded_before to a list request.
The request returns only the entries nobody downloaded since that time.
To clear every cached entry instead, go to the remote repository and select More actions ( ) > Clear cache.
Evicted entries cannot be restored. If the upstream has removed an image or package since it was cached, the evicted entry was the last copy.
| Format | List idle entries | Evict them |
|---|---|---|
| Docker and OCI | GET .../<format>/images?last_downloaded_before=<cutoff> | POST .../<format>/images/bulk_delete |
| Maven and npm | GET .../<format>/packages?last_downloaded_before=<cutoff> | POST .../<format>/packages/bulk_delete |
Rules for the cutoff:
- Use an absolute RFC 3339 time, such as
2026-10-01T00:00:00Z. A time in the future returns400 Bad Request. - Choose a cutoff at least one hour old. A pull can take up to an hour to update the download time, so a newer cutoff can list an entry someone just pulled.
- Compute the cutoff once and use it on every page. The
Linkheader keeps it for you.
On a hosted repository, last_downloaded_before returns 400 Bad Request.
Evict idle container images
This script evicts every cached image nobody pulled in the last 30 days. It reads each page of
idle images and sends one bulk delete for the page. Then it follows the Link header to the next
page.
Evict images, not manifests, to lower the repository’s stored size. Evicting an image removes its manifests, tags, and layers from the cache. Evicting only a manifest removes the manifest itself. The image’s layers stay cached and keep counting toward the repository’s stored size.
The script needs curl and jq, and expects AR_TOKEN, AR_HANDLE, AR_REPOSITORY, and
AR_FORMAT in the environment.
#!/bin/sh
set -eu
AR_HOST=https://artifact-registry.gitlab.com
API="$AR_HOST/api/v1/$AR_HANDLE/repositories/$AR_REPOSITORY/$AR_FORMAT"
CUTOFF=$(date -u -d "@$(( $(date +%s) - 30 * 86400 ))" +%Y-%m-%dT%H:%M:%SZ)
URL="$API/images?last_downloaded_before=$CUTOFF&limit=100"
while [ -n "$URL" ]; do
curl --silent --show-error --fail --dump-header headers.txt --output page.json \
--header "Authorization: Bearer $AR_TOKEN" "$URL"
if [ "$(jq length page.json)" -gt 0 ]; then
jq --compact-output '{image_ids: map(.id)}' page.json | curl --silent --show-error --fail \
--request POST \
--header "Authorization: Bearer $AR_TOKEN" \
--header "Content-Type: application/json" \
--data @- \
"$API/images/bulk_delete"
fi
next=$(grep -i '^link:' headers.txt | grep -o '<[^>]*>; rel="next"' | sed 's/^<\([^>]*\)>.*/\1/' || true)
URL=${next:+$AR_HOST$next}
doneThe Link header holds a path, so the script adds the host to it.
The repository’s stored size drops after the next background cleanup run, not when the request finishes.
Run the cleanup on a schedule
To evict idle images every week, run the script in a scheduled CI/CD pipeline. The job exchanges its job token for an Artifact Central token, so you store no secret.
Add the script to your project as
scripts/evict-idle-images.sh.Add a job to your
.gitlab-ci.ymlfile:evict-idle-images: image: alpine:3.22 rules: - if: $CI_PIPELINE_SOURCE == "schedule" variables: AR_HANDLE: <registry_handle> AR_REPOSITORY: <repository_name> AR_FORMAT: docker before_script: - apk add --no-cache curl jq - | AR_TOKEN=$(curl --silent --show-error --fail --request POST \ --header "JOB-TOKEN: $CI_JOB_TOKEN" \ "$CI_API_V4_URL/token_exchange?audience=gitlab-artifact-registry&expires_in=3600" | jq --exit-status --raw-output .token) test -n "$AR_TOKEN" export AR_TOKEN script: - sh scripts/evict-idle-images.shCreate a pipeline schedule, for example once a week.
The job runs as the schedule’s owner. That user needs the Artifact Manager role or higher on the remote repository.
Known issues
- Retention policies: You can’t set a policy that deletes artifacts on a schedule, such as “keep the last 10 versions.” Use a scheduled pipeline instead.
- Restore: Artifact Central keeps no trash, so you can’t restore a deleted artifact.
- Total storage: Deleting artifacts lowers each repository’s stored size, but your registry’s total storage doesn’t go down yet.