Keep only what matters using search-based retention rules

You can now use Cloudsmith’s package search syntax to refine the scope of your repository's retention rules when configuring them via the Cloudsmith API. This flexible query language lets you filter packages by tag, version, downloads, and more, making it easier to target exactly which packages to keep or remove.

By using the retention_package_query_string field when setting up your repository’s retention rules, you can apply policies to a specific subset of packages within the repository, such as:

  • Packages with no tags
  • Packages without a specific tag
  • Packages with fewer than 10 downloads

You can include multiple search filters, which work alongside existing configuration options like age limits, to enable smarter and more tailored retention policies. For example:

  • Delete packages that are older than 30 days AND have no tags AND have never been downloaded.

Sample query

Here is a sample query that deletes packages older than 180 days that do not have a "production" tag:

curl --request PATCH \
     --url https://api.cloudsmith.io/v1/repos/cloudsmith-test/acme-prod/retention/ \
     --header 'X-Api-Key: test-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "retention_enabled": true,
  "retention_days_limit": 180,
  "retention_package_query_string": "tag:~production"
}

What’s Next

We’re actively working on adding support for search-based retention rules to both the Cloudsmith web UI and the Terraform Provider, so you’ll be able to configure them wherever you work.

In the meantime, check out Retention Rules for more information on configuring package retention rules for your Cloudsmith repositories.

Keep up to date with our monthly product bulletin

By submitting this form, you agree to our privacy policy