0

I am trying to run jenkins with code to remove old build from artifactory ,i only need to keep last 10 builds in artifactory however the builds are not getting deleted frm artifacty` below is the snip of pipeline using

stage("Artifactory Upload") {
    def directory = "generic-local/ABC/XYZ/${params['version']}/${currDate}/${buildNo}/"
    def server = Artifactory.server 'art-int'
    def buildInfo = Artifactory.newBuildInfo()
    buildInfo.retention maxBuilds: 10, deleteBuildArtifacts: true
    
    
    

    def upload_spec_bin = """{
        "files": [
            {
                "pattern": "*",
                "target": "${directory}",
                "exclusions": ["*.txt"]
            }
        ]
    }"""
    
    server.upload spec: upload_spec_bin
    server.publishBuildInfo buildInfo
}
VSK
  • 21
  • 2
  • Can you please tell me if a specific build-name is having more than 10 build-numbers? Or your use case is to have just 10 overall builds? – Muhammed Kashif Jan 04 '22 at 08:28
  • @MuhammedKashif we need to store only last 10 builds A "log rotation" strategy should be implemented in the Jenkins pipeline to only store the last 10 builds – VSK Jan 04 '22 at 09:07
  • basically, from the pipeline script shared, let's say build name is "mybuild" which have 10 builds in it with each build-number under the "mybuild" build. Now when the same pipeline for "mybuild" is run for the 11th time, the 1st buildnumber under "mybuild" will be deleted. I'm a bit confused whether the overall builds to be restricted or the number of builds under the specific build to be restricted (The pipeline script does this restrictions) – Muhammed Kashif Jan 04 '22 at 14:50
  • @MuhammedKashif to simplify currently when i am running pipeline builds are saved in artifactory and the version keep on incrementing , for ex. i ran pipeline for 50 times 50 builds are storing in artifactory ... I dont want this ..................................................... What the expectation is to limit the build posting in artifactory to 10 (max) so pipeline for "mybuild" is run for the 11th time, the 1st buildnumber under "mybuild" will be deleted. – VSK Jan 04 '22 at 14:59
  • @MuhammedKashif any suggestions – VSK Jan 05 '22 at 09:59
  • refer here for the example https://github.com/jfrog/project-examples/blob/master/jenkins-examples/pipeline-examples/scripted-examples/vars-build-retention-example/Jenkinsfile – Muhammed Kashif Jan 06 '22 at 10:55
  • @MuhammedKashif I tried to implement the same but the old builds are not deleting from artifactory. Here is the code snip that i have implemented. – VSK Jan 07 '22 at 06:28
  • `stage("Artifactory Upload") { def directory = "generic-local/ABC/VK-test/${params['version']}/${currDate}/${buildNo}/" def server = Artifactory.server 'art-int' def buildInfo = Artifactory.newBuildInfo() buildInfo.env.capture = true buildInfo.env.collect() buildInfo.retention maxBuilds: 1,deleteBuildArtifacts: true def upload_spec_bin = """{ "files": [ { "pattern": "*", "target": "${directory}", "exclusions": ["*.txt"] } ] }""" build_info = server.upload spec: upload_spec_bin server.publishBuildInfo build_info }` – VSK Jan 07 '22 at 06:31
  • Does this answer your question? [Limit the number of builds stored in Artifactory](https://stackoverflow.com/questions/70494974/limit-the-number-of-builds-stored-in-artifactory) – yahavi Jan 08 '22 at 16:00

0 Answers0