Create a retention rule
A retention rule protects matching artifacts from all deletion types, including cleanup rules, manual soft delete, and manual hard delete. Retention rules are always evaluated first, regardless of rule order.
Any artifact that matches a retention rule cannot be deleted by any method. This includes scheduled cleanup rules, manual soft delete from the UI, and manual hard delete. To delete a protected artifact, you must first remove or disable the retention rule protecting it.
Before you begin
- Artifact Registry access: Project Admin or Artifact Registry Administrator role. Go to RBAC in Harness to configure roles.
- At least one registry: You need an existing registry to attach the rule to. Go to Create a Registry to set one up.
Name the rule
- Go to Artifact Registry > Registries Settings > Lifecycle Rules.
- Select + New Lifecycle Rule.
- Enter a Name for the rule.
- Add a Description (optional).
- Under Target, select Retention Rule.
- Select Next.
Configure scope and criteria
Configure which artifacts to protect. Retention rules do not have retention criteria or a schedule because they are always evaluated whenever a cleanup rule executes.
Registry scope
Select which registries this rule protects:
- All Registries: Applies to all registries under the current scope.
- Specific Registries: Select individual registries. When you choose this option, a Registries field appears where you search and select registries.
Package type
Select All Package Types or choose a specific format to narrow the protection scope.
Pattern filters
Optionally restrict which packages and versions are protected:
- Package Name Patterns: Wildcard patterns for package names (for example,
*-release,core-*). Use*as a wildcard and press enter to add multiple patterns. - Version Patterns: Wildcard patterns for version strings (for example,
v*.*.*,*-stable). Use*as a wildcard and press enter to add multiple patterns.
Select Submit to create the retention rule.
Retention rule evaluation
When a cleanup rule executes, the system:
- Identifies deletion candidates based on the cleanup rule criteria.
- Checks all applicable retention rules against those candidates.
- Removes any protected artifacts from the deletion set.
A retention rule does not run on its own schedule. It is applied automatically whenever a cleanup rule targets the same registries.
Protected artifact indicator
Artifacts protected by a retention rule display a Protected status badge. Hover over the badge to see which rule is protecting the artifact (for example, "Protected by my-retention-rule"). This helps you identify which rule to modify or disable if you need to delete the artifact.
Next steps
- Go to Lifecycle rules overview to understand the full evaluation flow.
- Go to Create a cleanup rule to set up automated artifact deletion.