node { def server def rtMaven = Artifactory.newMavenBuild() def buildInfo stage ('Clone') { git url: 'https://github.com/jfrog/project-examples.git' } stage ('Artifactory configuration') { // Obtain an Artifactory server instance, defined in Jenkins --> Manage Jenkins --> Configure System: server = Artifactory.server 'my-artifactory' // Tool name from Jenkins configuration, defined in Jenkins --> Manage Jenkins --> Global Tool Configuration --> Maven Installations --> Name rtMaven.tool = 'mvn' rtMaven.deployer releaseRepo: 'my-libs-release-local', snapshotRepo: 'my-libs-snapshot-local', server: server rtMaven.resolver releaseRepo: 'my-libs-release', snapshotRepo: 'my-libs-snapshot', server: server buildInfo = Artifactory.newBuildInfo() } stage ('Exec Maven') { rtMaven.run pom: 'maven-examples/maven-example/pom.xml', goals: '-DmavenLocalRepo="" -DmavenSettingsFilePath="" clean install -U', buildInfo: buildInfo } stage ('Publish build info') { server.publishBuildInfo buildInfo } }
In the above example, I created an Artifactory Maven Build instance ‘rtMaven’.
Under the ‘Artifactory configuration’ stage, I defined my Artifactory server as ‘my-artifactory’. This information can be found in Jenkins --> Manage Jenkins --> Configure System.
Then, I specified my maven tool name as ‘mvn’, which can be found in Jenkins --> Manage Jenkins --> Global Tool Configuration --> Maven Installations --> Name.
After that, I define my deployer and resolver repositories. Please note that the repositories should be defined accordingly as below:
rtMaven.deployer releaseRepo: ARTIFACTORY_LOCAL_RELEASE_REPO, snapshotRepo: ARTIFACTORY_LOCAL_SNAPSHOT_REPO, server: server rtMaven.resolver releaseRepo: ARTIFACTORY_VIRTUAL_RELEASE_REPO, snapshotRepo: ARTIFACTORY_VIRTUAL_SNAPSHOT_REPO, server: server
Lastly, I define my ‘buildInfo’.
The ‘Exec Maven’ and ‘Publish build info’ stages will execute maven goals and publish build info to Artifactory accordingly.