How to provide specific Jfrog arifactory path in Jenkins groovy script for retention strategy

Viewed 211

I want to use specific artifactory path for log rotation strategy. We need to keep only 5 latest builds in the artifactory. We are successfully able to load jenkins build to the specified artifactory path, however we are unable to link the path to buildInfo variable for deletion/retention. If we don't specify path it doesn't throw error but it goes to some default directory and doesn't delete build from the path specified in the manifest. We cannot use CURL as artifact configuration is defined at admin level. So username and password needs to be picked from environment variable.

stage('Artifactory: Upload and retention') {
def server = Artifactory.server 'abc-xyz'
def buildInfo = Artifactory.newBuildInfo()   

def upload_spec_bin = """{
    "files": [
        {
            "pattern": "${cyncapp_binary_name}",
            "target": "generic-local/orgproj/cyncapp/${env.BUILD_NUMBER}/"
        }
    ]
}"""
server.upload spec: upload_spec_bin

def upload_spec_manifest = """{
    "files": [
        {
            "pattern": "cyncapp_manifest.txt",
            "target": "generic-local/orgproj/cyncapp/${env.BUILD_NUMBER}/"
        }
    ]
}"""
server.upload spec: upload_spec_manifest

//def build_info = server.upload spec: upload_spec_manifest        
build_info.retention maxBuilds: 5,deleteBuildArtifacts: true        
server.publishBuildInfo buildInfo

}

1 Answers

There is no "path" in build-retention. The build retention should delete all artifacts of a build. To make sure the build-retention deletes your build artifacts, make sure to attach them to the buildinfo object, during the upload phase:

...
server.upload spec: upload_spec_bin, buildInfo: buildInfo
...
server.upload spec: upload_spec_manifest, buildInfo: buildInfo

After the job is finished, I'd recommend checking the published module in the builds tab in Artifactory UI, and making sure all artifacts are there.

Read more about build retention here:

  1. Triggering build retention
  2. Example
Related