CNB automatic clean plugin that supports cleaning repository Releases, Git Tags, and Docker image tags.
push_at)Control which resources to clean via the cleanType parameter:
| cleanType | Description |
|---|---|
release | Only clean Releases |
tag | Only clean Git Tags |
docker | Only clean Docker Image Tags |
all (default) | Clean all of the above |
Note: When
cleanTypeisdockerorall, ensure theCNB_REPO_SLUG_LOWERCASEenvironment variable is available, or specify it via theimageSlugparameter.
Specify filtering strategy via the filter parameter, in the format TYPE=PARAM:
| Filter Type | Format | Description | Applicable To |
|---|---|---|---|
TAGNAME_PREFIX | TAGNAME_PREFIX=v1. | Match by tag name prefix | Release / Tag / Docker |
NAME_PREFIX | NAME_PREFIX=build- | Match by name prefix | Release / Tag / Docker |
RECENT_N | RECENT_N=5 | Keep the most recent N, delete the rest | Release / Tag / Docker |
RECENT_N_DAYS | RECENT_N_DAYS=30 | Delete records older than N days | Release / Docker |
RECENT_N_DAYS_RETAIN_N | RECENT_N_DAYS_RETAIN_N=30,3 | Keep most recent N + delete others older than N days | Release / Docker |
Note:
RECENT_N_DAYSandRECENT_N_DAYS_RETAIN_Nare not applicable to Git Tags (Git Tags do not have aCreatedAtfield). Docker time-based filtering uses thelast_pusher.push_atfield.
Use in .cnb.yml pipeline configuration:
stages:
- name: auto-clean
image: docker.cnb.cool/r_r/auto-clean:latest
settings:
cleanType: "all"
filter: "RECENT_N_DAYS=30"
stages:
- name: auto-clean-releases
image: docker.cnb.cool/r_r/auto-clean:latest
settings:
cleanType: "release"
filter: "RECENT_N=10"
stages:
- name: auto-clean-docker
image: docker.cnb.cool/r_r/auto-clean:latest
settings:
cleanType: "docker"
imageSlug: "owner/my-repo" # Optional, defaults to CNB_REPO_SLUG_LOWERCASE
imageName: "my-image" # Optional, defaults to repo name
filter: "TAGNAME_PREFIX=v2024."
stages:
- name: auto-clean-preview
image: docker.cnb.cool/r_r/auto-clean:latest
settings:
cleanType: "all"
filter: "RECENT_N_DAYS_RETAIN_N=90,5"
dryRun: true
stringallrelease, tag, docker, allExample:
settings:
cleanType: "docker"
stringTYPE=PARAM. See Filter Rules above for details.Example:
settings:
filter: "RECENT_N_DAYS=60"
booleanfalsetrue, only outputs the list of items that would be deleted without performing actual deletions.Example:
settings:
dryRun: true
stringCNB_REPO_SLUG_LOWERCASE environment variablecleanType includes docker)Example:
settings:
imageSlug: "other-owner/image-repo"
stringimageSlug (repository name)cleanType includes docker.Example:
settings:
imageName: "my-app-image"
stringCNB_REPO_SLUG)stringhttps://api.cnb.cool.stringrepo-contents:rregistry:rWhether dry-run or not, the following pipeline variables are output:
##[set-output total-cleaned=15]
##[set-output cleaned-releases=5]
##[set-output cleaned-tags=8]
##[set-output cleaned-docker-tags=2]
Can be referenced in subsequent steps:
| Variable | Description |
|---|---|
total-cleaned | Total deleted count (sum of all types) |
cleaned-releases | Release deleted count (0 if cleanType does not include release) |
cleaned-tags | Git Tag deleted count (0 if cleanType does not include tag) |
cleaned-docker-tags | Docker Tag deleted count (0 if cleanType does not include docker) |
main:
push:
- stages:
- name: auto-clean
image: docker.cnb.cool/r_r/auto-clean:latest
settings:
cleanType: "all"
filter: "RECENT_N_DAYS_RETAIN_N=90,5"
dryRun: false
exports:
total-cleaned: TOTAL_CLEANED
cleaned-releases: CLEANED_RELEASES
cleaned-tags: CLEANED_TAGS
cleaned-docker-tags: CLEANED_DOCKER_TAGS
- name: echo result
script:
- echo "Total cleaned: $TOTAL_CLEANED"
- echo "Releases: $CLEANED_RELEASES"
- echo "Tags: $CLEANED_TAGS"
- echo "Docker Tags: $CLEANED_DOCKER_TAGS"
main:
push:
- stages:
- name: auto-clean-cross-repo
image: docker.cnb.cool/r_r/auto-clean:latest
settings:
slug: "other-owner/other-repo"
imageSlug: "other-owner/other-repo"
endpoint: "https://api.cnb.cool"
token: "${OTHER_REPO_TOKEN}"
cleanType: "all"
filter: "RECENT_N_DAYS=180"
When encountering API errors or missing parameters, the plugin will exit with a non-zero status code, causing the pipeline to fail. Common error scenarios:
cleanType value → shows supported type listfilter parameter → prompts required fieldfilter format → prompts correct format TYPE=PARAMImageSlug → prompts need for CNB_REPO_SLUG_LOWERCASE or manual imageSlugMIT License