# Cleanup and retention

> For AI agents: the complete documentation index is at https://buddy.works/llms.txt

Delete old artifact versions in Buddy with the Artifact Cleanup action and wildcard version patterns, and set retention rules in the artifact Settings tab.

The **Artifact Cleanup** action deletes artifact versions based on artifact name and version name patterns. All versions matching the configured patterns are deleted during action execution.

Individual versions can also be deleted manually on the Versions tab or using the `bdy artifact version delete` command. Both methods require the **Manage** permission level in the Artifacts module. See [Versions](https://buddy.works/docs/artifacts/versions.md).

## Artifact Cleanup action

Each row in the action configuration contains two fields: **Artifact name pattern** and **Version name pattern**. Additional rows can be added using the **+** button. Both fields support the `*` wildcard. For example, `build-*` matches all version names beginning with `build-`.

![Artifact Cleanup action form](https://buddy.works/docs/artifacts/artifacts-cleanup-action-form.png)

In YAML, the form rows are the `artifacts` list:

```yaml
- pipeline: cleanup-builds
  name: Clean up build versions
  refs:
  - refs/heads/main
  actions:
  - action: Delete build versions
    type: ARTIFACT_CLEANUP
    artifacts:
    - artifact: my-app-build
      version: build-*
```

Each deleted version has its own entry in the action log:

```
Deleting artifact version: my-app-build:build-3
```

![Artifact Cleanup action log](https://buddy.works/docs/artifacts/artifacts-cleanup-run-log.png)

The `artifacts` list can have several items, for example old builds of one artifact and test versions of another. Fields shared by all actions, such as `trigger_time` and `retry_count`, are described in the [action YAML reference](https://buddy.works/docs/yaml/yaml-actions/artifact-cleanup.md).

> **Warning**
>
> The `*` pattern matches all version names, including release versions. To limit deletion to temporary versions, use a dedicated version name prefix, such as `build-` or `pr-`, and a corresponding wildcard pattern. The `build-*` pattern does not match the `latest` version.

## Required permissions

The Artifact Cleanup action requires the **Manage** level for the pipeline. Read-write is not enough, even though it allows publishing versions.

A pipeline without the Manage level fails the action with this message:

```
Pipeline is not allowed to manage artifact: my-app-build
```

Open the artifact's **Permissions** tab, in the **Pipeline** section add the cleanup pipeline with the **+** button and set it to **Manage**. Do not raise the **All pipelines** row to Manage if only one pipeline should delete versions.

![Cleanup pipeline with Manage access](https://buddy.works/docs/artifacts/artifacts-permissions-pipeline-manage.png)

## When to run the cleanup

The Artifact Cleanup action can sit in a separate pipeline or at the end of the pipeline that publishes versions:

- **Separate pipeline on a schedule** - a pipeline with only the Cleanup action that runs periodically, for example once a week. Scheduling is described in [On schedule](https://buddy.works/docs/pipelines/introduction/triggering-pipelines/on-schedule.md).
- **Cleanup after a release** - the pipeline publishes a release version, for example `3.2.0`, and at the end deletes the `build-*` versions used for testing.

Before the first run, check in the **Versions** tab which versions match the pattern.

## Configure retention rules

You set retention rules in the artifact's **Settings** tab, in the **Retention** section. A rule consists of a version name pattern and one of these options:

- **Keep all versions** - nothing is deleted,
- **Keep the most recent** - the number of newest versions to keep,
- **Keep versions from the last** - the period from which versions are kept.

![Retention rule options in artifact settings](https://buddy.works/docs/artifacts/artifacts-settings-retention.png)

The Settings tab is available to a user whose role has the Manage level in the Artifacts module. In the REST API, the rules are the artifact's `retention_rules` field ([Artifacts API](https://buddy.works/docs/api/artifacts.md)).

> **Warning**
>
> A retention rule does not delete older versions when a new one is published. In tests with the **Keep the most recent** option, older versions matching the pattern were still on the list more than a day later. If versions must be gone at a specific time, use the Artifact Cleanup action.

## Storage and billing

Artifact storage is billed per GB-hour. Storage usage is listed as **Artifact GB-hours** on the Billing tab in workspace settings. For current storage rates, see [Usage and GB-minutes](https://buddy.works/docs/basics/billing-and-usage/gbmin.md).

See also:

- [Versions](https://buddy.works/docs/artifacts/versions.md) - deleting and copying versions manually
- [Artifacts in pipelines](https://buddy.works/docs/artifacts/pipelines.md) - Publish Artifact Version and Download Artifact Version actions
- [Permissions and access](https://buddy.works/docs/artifacts/permissions-and-access.md) - Deny, Read-only, Read-write and Manage levels
- [On artifact event](https://buddy.works/docs/pipelines/introduction/triggering-pipelines/on-artifact-event.md) - triggers started by version changes


---
Original source: https://buddy.works/docs/artifacts/cleanup-and-retention