0
votes

I have a Jenkinsfile and I want to be able to deploy maven build to different artifactory based on the build. For instance if the Jenkinsfile is triggered when I push my code to development branch I want to deploy the build from development branch to "maven-dev" artifactory. I have 4 Git branches (dev, preprod, stage, prod) and subsequently 4 different Artifactory locations (maven-dev, maven-preprod, maven-stage, maven-prod).

I have the following script in my Jenkinsfile for build deployment however, I need to know what changes I need to make to the following script in order to be able to deploy each build (mentioned above) to the corresponding Artifactory location?

script {
 def server = Artifactory.server('artifacts')
 def rtMaven = Artifactory.newMavenBuild()
 rtMaven.deployer server: server, releaseRepo: 'maven-prod', snapshotRepo: 'maven-dev'
 def buildInfo = rtMaven.run pom: 'pom.xml', goals: 'clean install -DskipTests=true -q -Dartifactory.publish.buildInfo=true'
 buildInfo = Artifactory.newBuildInfo()
 server.publishBuildInfo buildInfo
}
1
Not directly related to the question you're asking, notice that in the script sample you shared, you're publishing an empty build-info to Artifactory. This line - "buildInfo = Artifactory.newBuildInfo()" wipes out the build-info returned from the rtMaven.run method. You should probably remove this line.Eyal Ben Moshe
As for the question you're asking, there's a chance I didn't quite understand the challenge, but if you have the information of where you'd like to publish to, can you use an "if" statement to determine which values to put in "rtMaven.deployer"?Eyal Ben Moshe

1 Answers

0
votes

You should put all of the Artifactory server configurations in a "rtServer" block. This defines a new Artifactoruy server for this build, and you can configure different Artifactory instances in different builds by configuring different names in the "def server = Artifactory.server('NAME')" line, and give it the proper configuration (repository names, paths, etc). You can see this link for more information - https://www.jfrog.com/confluence/display/RTF/Declarative+Pipeline+Syntax#DeclarativePipelineSyntax-CreatinganArtifactoryServerInstance