Automatically purge packages according to a user-defined policy

You can create a package retention policy (policy.PackageRetentionPolicy) that removes all deployment packages except the last ‘N’ packages that match a regular expression that you define. Packages are sorted in lexicographical order.

Deployed packages are never removed by the package retention policy. If a deployed package is part of the packages identified for removal, then it will be skipped, with no impact on the other packages.

Automatically purge deployment packages

To automatically purge old deployment packages using a policy:

  1. From the side bar, click Configuration.
  2. Click Menu button, then select New > Policy > policy.PackageRetentionPolicy.
  3. In the Name field, type a unique policy name.
  4. In the Regex pattern field, specify a regular expression that matches the packages to which the policy should apply.
  5. In the Packages to retain field, type the number of deployment packages to retain per application.

Note: By default, automatic policy execution is enabled and will run according to the crontab scheduled defined on the Schedule tab. You can optionally change the crontab schedule or disable execution.

Tip: You can manually execute a package retention policy by right-clicking it and selecting Execute job now.

Creating multiple package retention policies

You can create multiple package retention policies. For example:


  • Regex pattern: ^Applications/.*/\d{1,8}(?:\.\d{1,6})?(?:\.\d{1,6})?(?:-\d+)?$
  • Packages to retain: 30
  • Schedule: 0 0 18 * * *


  • Regex pattern: ^Applications/.*/\d{1,8}(?:\.\d{1,6})?(?:\.\d{1,6})?(?:-\d+)?-SNAPSHOT$
  • Packages to retain: 10
  • Schedule: 0 0 18 30 * *

Important: Package retention policies are executed independently, so ensure that you define a regular expression that excludes packages that are covered by other policies.


An application has the following deployment packages:

  • 1.0
  • 2.0
  • 3.0
  • 3.0-SNAPSHOT
  • 4.0
  • 5.0

Package 1.0 is deployed to the PROD environment and 4.0 is deployed to the DEV environment.

Assuming a package retention policy that retains the last 3 packages and uses the ReleasePackagePolicy regular expression pattern defined above, the packages to be removed will be: 2.0.

From Deploy 10.0 and later, package versions that includes numerals (separated by dots) only will be sorted numerically.

For example, package versions 1.0, 5.90,, and 5.100 are sorted numerically as below:

  • 1.0
  • 5.90
  • 5.100

Similar sorting method applies to the purge policy and same reflects in the Deploy UI.