Jenkins Publish Using Maven Coordinates from the pom.xml

When you build and deploy to a Nexus repository using the Nexus Jenkins Plugin, you need to provide the artifact, group and version information to the Jenkins pipeline script. This information can be automatically extracted from the pom.xml using the readMavenPom Pipeline Utility Step.

Here is an example Publish stage from a Pipeline script:

stage('Publish') {
 def pom = readMavenPom file: 'pom.xml'
 nexusPublisher nexusInstanceId: 'nexus2', \
  nexusRepositoryId: 'releases', \
  packages: [[$class: 'MavenPackage', \
  mavenAssetList: [[classifier: '', extension: '', \
  filePath: "target/${pom.artifactId}-${pom.version}.${pom.packaging}"]], \
  mavenCoordinate: [artifactId: "${pom.artifactId}", \
  groupId: "${pom.groupId}", \
  packaging: "${pom.packaging}", \
  version: "${pom.version}"]]]
}

Make sure the Pipeline Utility Steps plugin is installed in Jenkins "Manage Plugins". If you do not have the plugin installed you may see an error: java.lang.NoSuchMethodError: No such DSL method 'readMavenPom' .

More information about configuring the Nexus Jenkins Plugin is available from the Nexus documentation.

Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk