> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/artifact-registry/use-artifact-registry/lifecycle-rules/create-cleanup-rule.md).

# Create a cleanup rule

A cleanup rule soft-deletes artifact versions that match your cleanup criteria on a recurring schedule. Deleted artifacts remain recoverable during the configured recovery period.

***

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

* **Artifact Registry access:** Project Admin or Artifact Registry Administrator role. Go to [RBAC in Harness](/harness-platform/3.0/harness-platform-resources/platform-access-control/rbac-in-harness.md) to configure roles.
* **At least one registry:** You need an existing registry to attach the rule to. Go to [Create a Registry](/artifact-registry/use-artifact-registry/manage-registries/create-registry.md) to set one up.

***

### Name the rule <a href="#name-the-rule" id="name-the-rule"></a>

1. Go to **Artifact Registry** > **Registries Settings** > **Lifecycle Rules**.
2. Select **+ New Lifecycle Rule**.
3. Enter a **Name** for the rule.
4. Add a **Description** (optional).
5. Under **Target**, select **Cleanup Rule**.
6. Select **Next**.

<figure><img src="/files/D3yiRIfPENVqGSc7Kkua" alt="About Rule step showing name, description, and target selection with Cleanup Rule selected"><figcaption><p>Step 1: Name the rule and select Cleanup Rule as the target</p></figcaption></figure>

***

### Configure scope and criteria <a href="#configure-scope-and-criteria" id="configure-scope-and-criteria"></a>

Configure what gets retained and what gets cleaned.

<figure><img src="/files/tVLUoLWhow4jfNSYjEQb" alt="Scope And Criteria step showing registry scope, package type, pattern filters, and cleanup criteria"><figcaption><p>Step 2: Define scope, filters, and cleanup criteria</p></figcaption></figure>

#### Registry scope <a href="#registry-scope" id="registry-scope"></a>

Select which registries this rule applies to:

* **All Registries:** Applies to all registries under the current scope.
* **Specific Registries:** Select individual registries to apply the rule to. When you choose this option, a **Registries** field appears where you search and select registries. Selected registries appear as tags in the field.

<figure><img src="/files/lI2xs2jRwXuBohSbG77G" alt="Scope And Criteria step with Specific Registries selected, showing swift-repo tag and Keep last 4 enabled"><figcaption><p>Scope and Criteria with specific registry selection</p></figcaption></figure>

#### Package type <a href="#package-type" id="package-type"></a>

Select **All Package Types** or choose a specific format (Docker, Maven, npm, etc.) to narrow the rule to a single package type.

#### Pattern filters <a href="#pattern-filters" id="pattern-filters"></a>

Optionally restrict which packages and versions the rule evaluates:

* **Package Name Patterns:** Wildcard patterns for package names (for example, `frontend-*`, `*-service`). Use `*` as a wildcard and press enter to add multiple patterns.
* **Version Patterns:** Wildcard patterns for version strings (for example, `1.0.*`, `*-SNAPSHOT`). Use `*` as a wildcard and press enter to add multiple patterns.

#### Cleanup criteria <a href="#cleanup-criteria" id="cleanup-criteria"></a>

You must select at least one criterion.

{% hint style="info" %}
**AND LOGIC**

When multiple criteria are enabled, **all** conditions must be true for a version to be deleted. For example, "Keep last 10" and "Older than 30 days" means a version is only deleted if it is beyond the 10 most recent **and** older than 30 days.
{% endhint %}

* **Keep last N versions:** Retain the most recent N versions on the package. Versions beyond this count become deletion candidates.
* **Delete artifacts older than X days:** Target versions created before the specified threshold.
* **Delete if not downloaded in last X days:** Target versions with no download activity within the specified window.

Select **Next**.

***

### Set the schedule <a href="#set-the-schedule" id="set-the-schedule"></a>

Define when the rule executes.

<figure><img src="/files/HQuJc09JW6cW3GgMtksh" alt="Schedule step showing timezone, frequency tabs, time picker, and generated cron expression"><figcaption><p>Step 3: Configure the execution schedule</p></figcaption></figure>

1. Select a **Timezone** (default: UTC).
2. Choose a frequency tab:
   * **Daily:** Set the time (hour, minute, AM/PM).
   * **Monthly:** Select the day of month and time.
   * **Yearly:** Select the month, day, and time.
   * **Custom:** Enter a cron expression directly.
3. Review the generated **Cron Expression** displayed below the time picker.
4. Select **Submit**.

The cleanup rule is created and executes as per the cron schedule. You can verify the rule on the Lifecycle Rules tab, where it shows the criteria summary, last run, and next run time.

{% hint style="info" %}
Use Dry Run from the rule actions menu (**⋮**) before the first scheduled execution to verify which artifacts would be affected.
{% endhint %}

***

### Next steps <a href="#next-steps" id="next-steps"></a>

* Go to [Lifecycle rules overview](/artifact-registry/use-artifact-registry/lifecycle-rules.md) to understand rule evaluation logic, dry runs, and execution history.
* Go to [Create a retention rule](/artifact-registry/use-artifact-registry/lifecycle-rules/create-retention-rule.md) to protect specific artifacts from cleanup.
* Go to [Delete Artifacts](/artifact-registry/use-artifact-registry/manage-artifacts/soft-delete.md) to understand soft-delete recovery.
