Jfrog Artifactory快照数量限制配置未生效,如何清理多余快照?
Hey there, I’ve run into this exact issue before—let’s break down what’s going on and how to fix it. That "Max Unique Snapshots per Version" setting you configured only kicks in for newly uploaded snapshots; it doesn’t automatically clean up the backlog of old snapshots that were already in your repo before you set the rule. Here’s how to get this sorted:
Before diving into cleanup, make sure your settings are applied correctly:
- Head to the Artifactory UI, navigate to your target snapshot repo (e.g., a Maven snapshot repository), click Edit
- Go to the Snapshot Handling section: confirm
Max Unique Snapshots per Versionis set to 1, and theDelete Old Snapshotscheckbox is ticked - Note: This rule works per version—so it only limits snapshots under the same version tag (like
1.0-SNAPSHOT). Snapshots from different versions (e.g.,1.1-SNAPSHOT) are counted separately, so don’t confuse that.
If you only have a handful of excess snapshots, the UI is straightforward:
- Navigate to the snapshot path in your repo (e.g.,
com/your-org/your-app/1.0-SNAPSHOT) - Select all the old snapshot files, leaving only the most recent one
- Click the Delete button at the top and confirm the action
For lots of snapshots, scripting with the Artifactory REST API is way more efficient. Here’s a quick workflow for Maven snapshots:
- First, fetch all snapshot files under a specific version:
curl -u your-username:your-password "http://your-artifactory-domain/artifactory/api/storage/your-snapshot-repo/com/your-org/your-app/1.0-SNAPSHOT?list&deep=1" - Parse the returned JSON to identify old snapshots (sort by timestamp to pick the latest one to keep)
- Delete unwanted snapshots with a DELETE request:
curl -u your-username:your-password -X DELETE "http://your-artifactory-domain/artifactory/your-snapshot-repo/com/your-org/your-app/1.0-SNAPSHOT/your-artifact-1.0-20240501.120000-1.jar" - If you’re comfortable with scripting, whip up a quick Python/Shell script to loop through all your snapshot versions, automatically keep the latest 1 per version, and delete the rest.
To avoid this backlog issue in the future, complement your repo’s snapshot limit with a Cleanup Policy:
- Go to Admin > Repositories > Cleanup Policies in the Artifactory UI
- Create a new policy: you can set rules like "Delete snapshots older than 7 days" or "Keep only 1 latest snapshot per version" (this will handle both new and existing snapshots over time)
- Attach the policy to your snapshot repo and set a schedule (e.g., run daily at 2 AM)
If even new snapshots aren’t being cleaned up, check these:
- Make sure you’re editing the correct repository—it’s easy to accidentally modify a different repo than the one storing your snapshots
- If this is a remote repo, the snapshot limit only applies to locally cached snapshots; the remote repo’s snapshots are controlled by the source
- Check Artifactory’s logs (
$ARTIFACTORY_HOME/logs/artifactory.log) for errors related to snapshot cleanup—look for permission issues or failed config loads
内容的提问来源于stack exchange,提问作者Kivi




