ARTIFACTORY: Cleanup Builds Artifacts in Artifactory

AuthorFullName__c
Fadi Rouhana
articleNumber
000006111
FirstPublishedDate
2024-05-28T09:44:54Z
lastModifiedDate
2025-07-20

ARTIFACTORY: Cleanup Builds Artifacts in Artifactory

Overview
Cleaning up build artifacts in Artifactory can be efficiently managed using either the REST API or the JFROG CLI. This process involves setting build retention policies to delete old builds and their associated artifacts, ensuring that the repository stays clean and manageable.

Methods to Set Build Retention
Using REST API
Build retention can be configured using the REST API. The endpoint for this is:
Control Build Retention - [REST API]

Using Jenkins Artifactory Plugin
To use this functionality in pipeline jobs, please refer to Build Retention Settings - [Jenkins Artifactory Plugin] or the Trigger Build Retention - [Scripted Pipeline Syntax] section on the Artifactory Pipeline APIs documentation page.  

Using JFROG CLI
Alternatively, you can discard old builds using the JFROG CLI command:
Discarding Old Builds from Artifactory - [JFROG CLI]

 
Changes in Build Retention from Version 7.68.14 Onwards

In earlier versions of Artifactory (below 7.68.14), the search and deletion of builds and artifacts were based on two parameters: build.name and build.number. This method allowed both builds and their associated artifacts to be deleted successfully whenever build retention policies were applied.

From Artifactory version 7.68.14 onwards, the process has been updated to include a third parameter: build.timestamp. This change enhances the accuracy of build artifact deletion processes.

Key Change

Pre-7.68.14: Deletion based on build.name and build.number.
Post-7.68.14: Deletion based on build.name, build.number, and build.timestamp.

System Property for Legacy Behavior
The change addresses situations where the same build name and build number are published multiple times. In such cases, the timestamp will be used as an identifier to distinguish which artifacts belong to which build.

Therefore, if you publish an identical build name and build number to the same build, it is recommended not to revert to the legacy behavior. However, if this is not a usage pattern adopted on your end, you may choose to revert to the legacy behavior.
To do so, a new system property has been introduced:

artifactory.build.forced.delete.artifacts



Property Details
  • Default Setting: true
  • When Set to false: Artifactory reverts to the legacy behavior and uses only build.name and build.number for searching build artifacts.

Changing this property to false will require a restart of Artifactory.


Setting the Property

To set this property, modify your Artifactory system properties $JFROG_HOME/artifactory/var/etc/artifactory/artifactory.system.properties file and include:

artifactory.build.forced.delete.artifacts=false

After making this change, restart Artifactory to apply the new setting.