Limit the number of builds stored in Artifactory

Hello Team,

I am trying to implement on my existing pipeline to limit the number of build stored in artifactory however it is not working .

A “log rotation” strategy should be implemented in the Jenkins pipeline to only store the last 5 builds This change should be made in the pipeline script itself .

    stage("Artifactory Upload") {
		def directory = "generic-local/ABC/XYZ/${params['version']}/${currDate}/${buildNo}/"
		def server = Artifactory.server 'art-int'
		
		def upload_spec_bin = """{
			"files": [
				{
					"pattern": "*",
					"target": "${directory}",
					"exclusions": ["*.txt"]
				}
			]
		}"""

		build_info = server.upload spec: upload_spec_bin
		build_info.retention maxBuilds: 5,deleteBuildArtifacts: true
		server.publishBuildInfo build_info
	}

Is your posted code pseudo code of what your trying to do?
Or is it failing to do what you want it to do? Is there an error message of some sort?

Wouldn’t retention be something that artifactory itself configure (I’ve never admined artifactory before)

I’m not sure what your “question” is.

Hello,

Yes its code that i am trying but it is not working as expected.
My expectation is to delete old build from artifactory using my jenkin pipeline.

what is it doing then?