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
- 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 Cleanup Rule.
- Select Next.
Configure scope and criteria
Configure what gets retained and what gets cleaned.
Registry scope
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.
Package type
Select All Package Types or choose a specific format (Docker, Maven, npm, etc.) to narrow the rule to a single package type.
Pattern filters
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
You must select at least one criterion.
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.
- 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
Define when the rule executes.
- Select a Timezone (default: UTC).
- 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.
- Review the generated Cron Expression displayed below the time picker.
- 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.
Use Dry Run from the rule actions menu (⋮) before the first scheduled execution to verify which artifacts would be affected.
Next steps
- Go to Lifecycle rules overview to understand rule evaluation logic, dry runs, and execution history.
- Go to Create a retention rule to protect specific artifacts from cleanup.
- Go to Delete Artifacts to understand soft-delete recovery.