Introduction
Administrators often need to create Retention Policies that target artifacts residing only within specific subfolders of a repository. However, the current native Retention Policy interface allows scoping by Repository or Project, but does not support defining scope by specific internal subfolder paths.
Attempting to manage cleanup for specific project paths or folder structures without this feature can be challenging.
This article will walk you through a property-based workaround that allows you to target specific subfolders for cleanup by "tagging" the artifacts you wish to remove.
Resolution
To achieve subfolder-specific cleanup, we use a two-step logic: Tag and Delete. Instead of telling the policy where to look (which isn't supported), we label the artifacts so the policy knows what to target.
Step-by-Step Instructions
Phase 1: Identify and Tag Target Artifacts
First, you must apply a specific property (e.g., cleanup=true) to the artifacts located in the desired subfolder. This can be done using the JFrog CLI or the REST API.
-
Define your criteria: Determine which subfolder path you want to target (e.g., example-repo-local/test/*).
-
Apply the Property: Use the JFrog CLI to set a property on all items within that path.
Phase 2: Configure the Retention Policy
Once the artifacts are tagged, configure the Retention Policy to look for that specific property.
-
Log into the JFrog Platform UI as an Administrator.
-
Navigate to Administration > Artifactory Settings > Retention Policies.
-
Click Create Policy.
-
Select the repository containing your target subfolders in Include Repository Patterns.
-
Policy Conditions:
-
Set your time-based criteria (e.g., artifacts older than 30 days).
-
Locate the Property section.
-
Add a condition: Key: cleanup, Value: true.
-
Save and then perform a Dry Run to verify that only the tagged artifacts in your subfolder are selected.
Conclusion
By marking specific subfolders with a custom property, you can effectively bypass the current limitation regarding path-based Retention Policies. The Retention Policy will scan the entire repository but will only act on items possessing the specific tag you applied.