Home > Mobile >  Jenkins - convert current declarative pipeline to Maven upload pipeline
Jenkins - convert current declarative pipeline to Maven upload pipeline

Time:07-26

in Jenkins declarative pipeline I have a job that currently successfully uploads ZIP package to Artifactory Generic repo. First I run npm install and npm build scripts, and new generated folder I ZIP it and send to artifactory.

sh "npm install"
............
sh "npm run build:qa"
................
            stage ('Artifactory stage') {
                steps {
                    rtServer (
                        id: 'Artifactory',
                        url: 'https://artifactory.domain.dev/artifactory',
                        credentialsId: 'id'
                    )
                }
            }

        stage ('Build info stage ') {
            steps {
                rtBuildInfo (
                    maxBuilds: 50,
                    deleteBuildArtifacts: true
                )
            }
        }

        stage ('Upload stage') {
            steps {
                rtUpload (
                    serverId: 'Artifactory',
                    spec: '''{
                          "files": [
                            {
                              "pattern": "arena*.zip",
                              "target": "my-generic-snapshot-local/packages/"
                            }
                         ]
                    }''',
                )
            }

Now, the same ZIPPED file I would like to send to Maven repo - test-maven-snapshot-local. I saw on this link https://www.jfrog.com/confluence/display/JFROG/Declarative Pipeline Syntax that I should define rtMavenResolver rtMavenDeployer and rtMavenRun. I would like to keep npm install and build logic.

But how do I specify in rtMaven* which zip package I want to UPLOAD to artifactory? I can't find that part. Also how to define a name of the package how it should be uploaded? also if I want to specify a subfolder of the repo where I want to upload how I could do that? will the pom file be automatically generated?

Can someone help me how I should define those 3 methods?

UPDATE!!!: I have modified my Jenkinsfile:

                rtServer (
                    id: 'Artifactory',
                    url: 'https://artifactory.fis.dev/artifactory',
                    credentialsId: '9134676',
                    timeout: 300
                )

                rtMavenDeployer (
                id: "MAVEN_DEPLOYER",
                serverId: "Artifactory",
                releaseRepo: "my-generic-release-local",
                snapshotRepo: "my-generic-snapshot-local"
                )

                rtMavenResolver (
                    id: "MAVEN_RESOLVER",
                    serverId: "Artifactory",
                    releaseRepo: "apache-maven-remote",
                    snapshotRepo: "apache-maven-remote"
                )

........................

stage ('Exec Maven') {
    steps {
        rtMavenRun (
            tool: "maven-3.2.5", // Tool name from Jenkins configuration
            pom: 'pom.xml',
            goals: 'clean install',
            deployerId: "MAVEN_DEPLOYER",
            resolverId: "MAVEN_RESOLVER"
        )
    }
}

I specified in my pom.xml file name of the folder with artifacts. <artifactId>arena-web-ruf</artifactId>

As a result - I get arena-web-ruf-2022.3-SNAPSHOT.pom arena-web-ruf-2022.3-SNAPSHOT.jar

but .JAR file doesn't contain any useful info except: META-INF file with pom.xml and pom.properties file. No code at all.

I would preffer as a result of the Jenkins build to have a ZIPPED package with code on Artifactory.

Thanks

CodePudding user response:

I don't think you need to worry about rtMavenResolver rtMavenDeployer and rtMavenRun, you can simply add another block to your existing rtUpload step, with the maven repo as the target (assuming it's on the same Artifactory instance).

spec: '''{
      "files": [
        {
          "pattern": "arena*.zip",
          "target": "my-generic-snapshot-local/packages/"
        },
        {
          "pattern": "arena*.zip",
          "target": "my-maven-snapshot-local/packages/"
        }
     ]
}''',
  • Related