1
votes

I am using the Jenkins-Artifactory plugin to deploy a jar file to a repo in Artifactory. Build tool being used is gradle. The process does not seem to maintain multiple timestamped versions of the jar artifact.

The repository uses 'gradle-default' layout. Maven snapshot version behavior has been set to 'Unique'. Max unique snapshots set to 30.

I am using rtUpload and rtPublishBuildInfo to upload the jar and corresponding buildinfo to Artifactory.

I see multiple versions of buildinfo under 'artifactory-build-info' repository in format BUILDNUMBER_TIMESTAMP.json However the application jar is being overwritten every time with name as appname-VERSION.jar, thus keeping only the latest version in repo.

I have tried changing Maven snapshot version behavior to 'Non-Unique' and adding 'SNAPSHOT' to version string. This did not resolve the issue

pipeline code for uploading artifacts

// upload build artifacts to artifact repository
        stage('publish to artifactory') {
          steps {
            rtUpload (
                serverId: "ARTIFACTORY_SERVER_ID",
                spec:
                  """{
                    "files": [
                      {
                        "pattern": "kotlin-source/build/libs/appname-*.jar",
                        "target": "gradle-dev-local"
                      }
                    ]
                  }""",
                failNoOp: true,
            )
          }
        }
        stage ('Publish build info') {
           steps {
              rtPublishBuildInfo (
                serverId: "ARTIFACTORY_SERVER_ID",
               )
           }
        }

expected multiple artifacts to be present in the repo with timestamp appended to the name. Only a single jar is seen under the repo. After the artifact is published, existing jar in the repo is moved to Trash Can

1

1 Answers

2
votes

The way unique snapshots work is when the setting is set to UNIQUE and the repo layout is Maven (or Gradle) snapshots, and the file is deployed with a SNAPSHOT version according to the layout, Artifactory will rename it on the fly to contain Maven unique snapshot ID.

Maven publication will take care of the snapshot version, and Artifactory will take care of making those snapshots unique (and cleanups). You only need to make sure your version string ends with -SNAPSHOT.