0
votes

I am able to integrate jenkins with artifactory to store my artifacts whenever a build is carried out, however whenever new artifacts are being pushed, the older versions will be removed automatically.

So I will like to check is there anyway for me to label each artifacts according to the version number or build number for easy version control.

1

1 Answers

1
votes

Be sure to include the Jenkins ${env.BUILD_NUMBER} in the artifact path and name.

Assuming your Artifactory repository is set up as a Maven repository your pipeline should include something like this:

def uploadSpec = """{
    "files": [
        {
            "pattern": "${env.PACKAGING_FOLDER}/${env.REPOSITORY_APPLICATION}-${env.BUILD_NUMBER}.zip",
            "target": "${env.REPOSITORY_CODE}/${env.REPOSITORY_GROUP}/${env.REPOSITORY_APPLICATION}/${env.BUILD_NUMBER}/${env.REPOSITORY_APPLICATION}-${env.BUILD_NUMBER}.zip",
            "regexp": "true"
        }
    ]
}"""

def buildInfo = Artifactory.newBuildInfo()
buildInfo.env.capture = true

buildInfo = server.upload(uploadSpec)
server.publishBuildInfo(buildInfo)