Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
{jenkins-plugin-info:pipeline-maven}

 


Introduction

Excerpt

Provides Maven integration with Pipeline Plugin by using the withMaven step, which configures a maven environment to use within a pipeline job by calling sh mvn or bat mvn.

...

An example pipeline script using the pipeline Maven plugin:

Code Block
languagegroovyjava
titleMaven build on a Linux agent
node{
  stage ('Build') {

    git url: 'https://github.com/cyrille-leclerc/multi-module-maven-project'

    withMaven(
        // Maven installation declared in the Jenkins "Global Tool Configuration"
        maven: 'M3maven-3',
        // Maven settings.xml file defined with the Jenkins Config File Provider Plugin
        // We recommend to define Maven settings.xml andglobally globalat settingsthe canfolder alsolevel beusing defined in Jenkins Global Tools Configuration
    
        // navigating to the folder configuration in the section "Pipeline Maven Configuration / Override global Maven configuration"
   mavenSettingsConfig: 'my-maven-settings',    // or globally to  mavenLocalRepo: '.repositorythe entire master navigating to  "Manage Jenkins / Global Tools Configuration"
        mavenSettingsConfig: 'my-maven-settings') {

      // Run the maven build
      sh "mvn clean installverify"

    } // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe reports& and FindBugs & SpotBugs reports...
  }
}

Withn Within a node or a docker.image block, create a withMaven block to setup a with maven environment. The configured environment will be used when calling maven inside the block by using sh mvn or bat mvn. The following parameters can be used to configure maven:

...

The "withMaven()" pipeline step will setup the Maven settings file and global settings file either explicitly using the attributes of the "withMaven(){}" step declaration or implicitly using the Maven Global Settings and Settings files defined at the folder level or in the Jenkins Global Tools Configuration.

Using implicit declaration, Jenkins administrators can simplify the work of pipeline authors hiding the "boilerplate" to declare the credentials of the Git, Nexus, Artifactory... servers and all the needed proxies, mirrors...

Image Added

Image Added

Traceability of Maven builds

...

No Format
[withMaven] use JDK installation JDK8
[withMaven] use Maven installation 'M3'
[withMaven] use Maven settings provided by the Jenkins Managed Configuration File 'maven-settings-for-supply-chain-build-job'
[withMaven] use Maven settings.xml 'maven-settings-for-supply-chain-build-job' with Maven servers credentials provided by Jenkins (replaceAll: true):
     [mavenServerId: 'nexus.beescloud.com', jenkinsCredentials: 'beescloud-nexus-deployment-credentials', username: 'deployment', type: 'UsernamePasswordCredentialsImpl'],
     [mavenServerId: 'github.beescloud.com', jenkinsCredentials: 'github-enterprise-api-token', username: 'dev1', type: 'UsernamePasswordCredentialsImpl']
...
Running shell script
+ mvn clean deploy
----- withMaven Wrapper script -----
Picked up JAVA_TOOL_OPTIONS: -Dmaven.ext.class.path=".../pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="..."
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /home/ubuntu/jenkins-home/tools/hudson.tasks.Maven_MavenInstallation/M3
Java version: 1.8.0_102, vendor: Oracle Corporation
Java home: /home/ubuntu/jenkins-home/tools/hudson.model.JDK/JDK8/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-109-generic", arch: "amd64", family: "unix"

...

Report Publishers

Maven build executions inside the "withMaven(){...}" will be detected and Jenkins will transparently

...

Reporter

Description

Required Jenkins Plugin (1)

Configuration to disable the feature

Since v2.3.0 (2)

Marker file to disable the feature (3)

Generated Artifact

Archiving and the fingerprinting of the artifacts and attached artifacts generated by the Maven build (jar, sources jar, javadocs jar...)

 


withMaven(options: [artifactsPublisher(disabled: true)],...)

`.skip-archive-generated-artifacts`

Generated JUnit, Surefire and FailSafe reports

Publishing of the JUnit, Surefire and FailSafe reports generated by the Maven build

JUnit Plugin

withMaven(options: [junitPublisher(disabled: true)],...)

`.skip-publish-junit-results`

Generated Findbugs reports

Publishing of the Findbugs reports generated by the Maven build

FindBugs Plugin

withMaven(options: [findbugsPublisher(disabled: true)],...)

`.skip-publish-findbugs-results`

Tasks scanner report

Publishing of a report of the "FIXME" and "TODO" tasks found in the java source code. The keywords can be configured.

Jenkins Tasks Scanner Plugin

withMaven(options: [openTasksPublisher(disabled: true)],...)

`.skip-task-scanner`

Dependencies Fingerprinting

(since 2.5.0)

Fingerprint the Maven dependencies.

By default only the snapshot dependencies of scope compile, runtime and provided are fingerprinted.

 
withMaven(options: [dependenciesFingerprintPublisher(disabled: true)],...)`.skip-fingerprint-maven-dependencies`

Concordion test report

(since 3.0.0)

Publishing of the Concordion test reports.

Publish the Concordion reports generated by the maven-surefire-plugin:test and the maven-failsafe-plugin:integration-test goals and located in the folder described by the system property "concordion.output.dir" as documented in Concordion > Integration > Java > Maven

 


HTML Publisher PluginwithMaven(options: [concordionPublisher(disabled: true)],...)`.skip-publish-concordion-results`
Maven Invoker Plugin test reportsPublish test reports generated by the maven-invoker-plugin:run goal
Maven Invoker Plugin
withMaven(options: [invokerPublisher(disabled: true)],...)`.skip-publish-invoker-run`
JGiven reportsPublish JGiven test reportsJGiven PluginwithMaven(options: [jgivenPublisher(disabled: true)],...)`.skip-publish-jgiven-results`
JaCoCo Code CoveragePublish JaCoCo Code CoverageJaCoCo Plugin

withMaven(options: [jacocoPublisher(disabled: true)],...)


Maven Linker Publisher

Publish the Maven report on the pipeline build GUI (list of dependencies, produced artifacts, downstream & upstream pipelines).

This publisher should be renamed "Maven Build Report Publisher".

A reason to disable this publisher is typically to not "pollute" the build screen with Maven invocations when Maven is used as an utility (e.g. invocations of "maven-help-plugin:3.2.0:evaluate"...)


withMaven(options: [mavenLinkerPublisher(disabled: true)],...)`skip-maven-linker-publisher`
Pipeline Graph PublisherBuild the graph of dependencies between Jenkins pipelines and Maven artifacts in order to trigger downstream pipelines (when using the `snapshotDependencies` on downstream pipelines)
withMaven(options: [pipelineGraphPublisher(disabled: true)],...)`.skip-pipeline-graph`

(1) Jenkins Plugin to publish the reports on the Jenkins build page. If the plugin is not installed, then the MAven report is ignored.

(2) Download pipeline-maven-2.3.0-beta-1.hpi

(3) Experimental feature.
Marker  Marker file to temporarily disable the feature for a specific Maven build.
Typically used to disable a reporter for a specific build that would generate too much data for the default configuration of the reporter (e.g. too many generated artifacts...) or to workaround a bug in the "withMaven" waiting for a fix. These marker file must be located in the home directory of the build.

Global Default Configuration

The default configuration of the Maven settings, global settings and the publishers can be defined in the "Global Tool Configuration" screen.

Image Removed

Implicit or Explicit activation of Publishers

By default, all the publishers are enabled by default.

It is possible to change the default activation of a publisher navigating to the "Global Tool Configuration" screen.

It is possible to disable the default activation of publishers on a specific "withMaven(){...}" step using the "publisherStrategy='EXPLICIT'" attribute in the step "withMaven(publisherStrategy='EXPLICIT'){...}". The publishers can then be enabled explicitly in the "withMaven(){...}" step using the "publishers" attribute

Default Configuration

Default Maven settings can be defined globally and at the folder level.

Global Default Configuration

In the "Global Tool Configuration" screen

  • Maven settings and Maven global settings 
  • Publishers settings: enable/disable publishers...

Image Added

Folder Level Configuration

In the Folder "configuration" screen

  • Maven settings and Maven global settings 

Image Added

Trigger downstream pipeline when a snapshot is built (since 3.0.0)

...

  • The upstream artifact must be generated in a "withMaven(){}" wrapping step to be detected by the triggering system
  • The downstream pipeline must have selected the build trigger "Build whenever a SNAPSHOT dependency is built"
    • The build trigger can be defined at the pipeline level ("Build Triggers"), at the multibranch pipeline level ("Scan Repository Triggers") or at the GitHub Organization / Bitbucket Project level ("Scan Organizations Triggers")
  • You have to manually trigger once the upstream pipeline and the downstream pipeline so that the link between the pipelines based on the SNAPSHOT dependency is established
  • The dependency graph is, for the moment, exclusively stored in an H2 embedded database ("$JENKINS_HOME/jenkins-jobs/jenkins-jobs.mv.db"). Support for an external H2 database and then for alternate databases (PostgreSQL) is on the roadmap (see PipelineMavenPluginH2Dao.java)

Image Modified

Image Added

Downstream Pipeline Trigger - Org Level ConfigurationImage Added

  • Thresholds are applied to define on which type of maven build the downstream pipelines are triggered
    • Threshold based on the status of the upstream pipeline ("success", "unstable", "failure", "no build", "aborted"). By default, only builds with a "success" result will trigger downstream builds.
      • Image Added
    • Threshold based on the Maven lifecycle phase reached in the Maven build of the upstream job ("package", "install", "deploy"). By default, only the maven builds who reach the "deploy" phase will trigger downstream builds.
      • Image Added

Linux, Windows and MacOSX support

The Pipeline Maven Plugin works with Linux, Windows and MacOSX build agents.

Code Block
languagegroovyjava
titleMaven build on a Windows agent
node ("windows") {
  stage ('Build') {

    git url: 'https://github.com/cyrille-leclerc/multi-module-maven-project'

    withMaven(...) {

      bat "mvn clean install"

    } // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe reports and FindBugs reports
  }
}

Support of Takari's Maven Wrapper 'mvnw' (since 3.0.3)

The Pipeline Maven Plugin works with Takari's Maven wrapper 'mvnw'.

Code Block
languagejava
withMaven(...) {
   sh "./mvnw clean deploy"
}
...


Adding more Maven Reporters

The API for Maven reporters is still experimental. Please open a Request for Enhancement Jira issue to discuss how to add Maven reporters.

We want to quickly add reporters for CheckStyle, Jacoco...

Setup

Using a MySQL Database (since 3.6.0)

The Jenkins Pipeline Maven Plugin relies on a database to store its data (list of dependencies and of generated artifacts of each build...).

By default, the Jenkins Pipeline Maven Plugin uses an H2 embedded database but it is recommend to use an external MySQL database.

Configuration steps to use a MySQL:

  • Create an empty MySQL database with a dedicated MySQL user with permissions for Data Manipulation Language actions (DML) and Data Definition Language (DDL) actions
    • Tested with MySQL 8.0, with MariaDB 10.2 and 10.3 and with Amazon Aurora MySQL 5.6
  • Install the Jenkins "MySQL Database" plugin
    • Navigate to "Manage Jenkins / Manage Plugins / Available", select the "MySQL Database" plugin and click on "Download now and install after restart"
  •  Configure the Pipeline Maven Plugin to use the created MySQL database
    • Create Jenkins credentials for the MySQL connection navigating to "Credentials" on the left menu
    • Navigate to "Manage Jenkins / Global Tools Configuration" and go to the "Pipeline Maven Configuration"
    • Image Added
    • In the Database configuration section, define the following
      • JDBC URL: url of the database, e.g. "jdbc:mysql://mysql.example.com/jenkins"
      • JDBC Credentials: select the credentials of the MySQL database
      • The parameters recommended by the Hikari Connection Pool team are used by default for the MySQL connections and for the datasource (max pool size:10, server side prepared statements cache with 250 entries...).  To overwrite these defaults, click on the "Advanced Database Convfiguration" button.
    • Click on "Validate Database Configuration" button to verify that the connection is successful
    • Click on "Save"
    • Image Added


Using a PostgreSQL Database (since 3.7.0)

The Jenkins Pipeline Maven Plugin relies on a database to store its data (list of dependencies and of generated artifacts of each build...).

By default, the Jenkins Pipeline Maven Plugin uses an H2 embedded database but it is recommended to use an external PostgreSQL or MySQL / MariaDB database.

Configuration steps to use a PostgreSQL:

  • Create an empty PostgreSQL database with a dedicated PostgreSQL user with permissions for Data Manipulation Language actions (DML) and Data Definition Language (DDL) actions
    • Tested with PostgreSQL 10.6 and 11.3
  • Install the Jenkins the "PostgreSQL API" plugin
    • Navigate to "Manage Jenkins / Manage Plugins / Available", select the "PostgreSQL API" plugin and click on "Download now and install after restart"
  •  Configure the Pipeline Maven Plugin to use the created PostgreSQL database
    • Create Jenkins credentials for the PostgreSQL connection navigating to "Credentials" on the left menu
    • Navigate to "Manage Jenkins / Global Tools Configuration" and go to the "Pipeline Maven Configuration"
    • Image Added
    • In the Database configuration section, define the following
      • JDBC URL: url of the database, e.g. "jdbc:postgresql://postgresql.example.com:5432/jenkins"
      • JDBC Credentials: select the credentials of the PostgreSQL database
      • The underlying datasource, HikariCP, comes with sensible default configuration values (see here). To overwrite these defaults, click on the "Advanced Database Configuration" button.
    • Click on "Validate Database Configuration" button to verify that the connection is successful
    • Click on "Save"
    • Navigate to "Manage Jenkins / Global Tools Configuration" and go to the "Pipeline Maven Configuration" to verify that the database connection is successful and the database tables have been created (see screenshot above)

FAQ

Anchor
withMavenAndDockerPipeline
withMavenAndDockerPipeline

How to use the Pipeline Maven Plugin with Docker? (since version 3.0.3)

Since the version 1.14 of the Docker Pipeline plugin, "withMaven" requires to

  • Either prepend the 'MVN_CMD_DIR' environment variable to the 'PATH' environment variable in every 'sh' step that invokes 'mvn' (e.g. "sh 'export PATH=$MVN_CMD_DIR:$PATH && mvn clean deploy' ").
  • Or use Takari's Maven Wrapper (e.g. "sh './mvnw clean deploy'")

If omitted, the Maven settings file and Mven global settings file will not be injected in the Maven execution.

Using "withMaven" with "docker.image(...).inside{...}" and a Jenkins Scripted Pipeline 

Code Block
languagejava
titlePrepending MVN_CMD_DIR to PATH
node("linux-agent-running-docker") { // Linux agent with the Docker daemon
    docker.image('maven').inside { // Docker image with Maven installed
        withMaven(...) {
            git "https://github.com/cyrille-leclerc/my-jar.git"
            sh "export PATH=$MVN_CMD_DIR:$PATH && mvn clean deploy" // 'mvn' command: need to add the $MVN_CMD_DIR to $PATH
        }
    }
}

 

Code Block
languagejava
titleUsing Takari's Maven Wrapper mvnw
node("linux-agent-running-docker") { // Linux agent with the Docker daemon
    docker.image('openjdk:8-jdk').inside { // Docker image with Java installed
        withMaven(...) {
            git "https://github.com/cyrille-leclerc/my-jar.git"
            sh "./mvnw clean deploy" // 'mvnw' command (e.g. "./mvnw deploy")
        }
    }
}


Using "withMaven" with "docker.image(...).inside{...}" to a Jenkins Declarative Pipeline 

TODO provide a sample with Jenkins Declarative Pipeline

 


Sample message displayed in the build logs when using withMaven in a Docker Pipeline execution environment

Warning message displayed in the logs when invoking withMaven within Docker Pipeline:

No Format
[withMaven] WARNING: "withMaven(){...}" step running within "docker.image('image').inside {...}". Since the Docker Pipeline Plugin version 1.14, you MUST:
[withMaven] * Either prepend the 'MVN_CMD_DIR' environment variable to the 'PATH' environment variable in every 'sh' step that invokes 'mvn' (e.g. "sh 'export PATH=$MVN_CMD_DIR:$PATH && mvn clean deploy' "). 
[withMaven] * Or use Takari's Maven Wrapper (e.g. "sh './mvnw clean deploy'")
[withMaven] See Pipeline Maven Plugin FAQ.


How to disable the Maven Event Spy injected by the Pipeline Maven Plugin in Maven builds?

...

  • Setting the environment variable "JENKINS_MAVEN_AGENT_DISABLED" to "true" in the job execution

 


Code Block
languagebash
...
withMaven() {
   sh """
export JENKINS_MAVEN_AGENT_DISABLED=true
mvn package
"""
}
Code Block
languagebash
...
withEnv(['JENKINS_MAVEN_AGENT_DISABLED=true']) {
   sh "mvn package"
}

 


  • Adding the system property "-Dorg.jenkinsci.plugins.pipeline.maven.eventspy.JenkinsMavenEventSpy.disabled=true" to the invocation of the mvn build

...

No Format
[WARNING] Picked up JAVA_TOOL_OPTIONS: -Dmaven.ext.class.path="/path/to/workspace/...@tmp/withMaven.../pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/path/to/workspace/...@tmp"

(info) It is not possible to disable this warning message

My downstream pipelines don't get triggered even if I use "Build whenever a SNAPSHOT dependency is built"

A common reason why downstream pipelines don't get triggered when using "Build whenever a SNAPSHOT dependency is built" is that the upstream pipeline is using "mvn install" when the Jenkins Pipeline Maven integration is configured to trigger pipelines on "mvn deploy".

To configure the Jenkins Pipeline Maven integration to trigger downstream pipelines on "mvn install":

  • Either change the default configuration:
    • Navigate to "Manage Jenkins / Global Tools Configuration"
    • Click on "Add Publisher" and select "Pipeline Graph Publisher"
    • In the section "Downstream Pipeline Triggers", change the the "Maven lifecycle threshold" from "deploy" to "install"

Image Added

  • Or in the script of the upstream pipeline, configure "withMaven(options: [pipelineGraphPublisher(lifecycleThreshold: 'install')]) {...}"


How can I troubleshoot problems of trigger of downstream pipelines

  • The Pipeline Maven Plugin uses the Jenkins log levels (see here) to output additional troubleshooting information in the pipeline build logs (the "Console Output" menu of the build)
  • To output additional troubleshooting information about the  trigger of downstream pipelines, enable in "Manage Jenkins / System Log" (docs here)  the following loggers at a level FINE or FINER or more:
    • org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher
    • org.jenkinsci.plugins.pipeline.maven.listeners.DownstreamPipelineTriggerRunListener
  • Re run the pipeline that is supposed to trigger downstream pipelines.
  • Look at the pipeline build logs ("Console Output" menu), ensure that the build is completed and that the following message is displayed in the logs: "[withMaven] downstreamPipelineTriggerRunListener - completed in XXX ms". Troubleshooting details are added

How do I capture the log file generated by the Jenkins Maven Event Spy

...

Code Block
withMaven(){
   mvn help:effective-settings
}

Known Limitations

Maven and JDK installers do not work with "docker.image('xxx').inside{...}" as the docker step does not allow the use of Tool Installer, the preinstalled Maven and JDK on the docker image will be auto-discovered and used.

Changelog

3.0.0-beta-1 (2017-08-07)

 

  • JENKINS-44721 Trigger pipelines that depend on generated snapshot artifacts
    • select the build trigger "Build whenever a SNAPSHOT dependency is built" on the downstream pipelines
      Image Removed
    • manually trigger once the upstream pipeline and once the downstream pipeline so that each of them is "registered" in the "pipeline dependency graph"
    • when the upstream and downstream jobs are registered, the following messages will be displayed in the build logs when an upstream pipeline triggers a downstream pipeline:
    • Message in the logs of the upstream pipeline build: "[withMaven] Scheduling downstream pipeline my-downstream-pipeline#7..."
    • Message in the build logs of the downstream pipeline: "Started by upstream project 'my-upstream-pipeline' build number 5"
  • JENKINS-45674 Automatically publish Concordion reports
  • JENKINS-45265 Automatically publish test reports generated by the [maven-invoker-plugin](https://maven.apache.org/plugins/maven-invoker-plugin/)

Download: https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/pipeline-maven/3.0.0-beta-1/pipeline-maven-3.0.0-beta-1.hpi

 

2.5.2

  • JENKINS-45221 Use case insensitive path when computing the workspace relative path

2.5.1

  • JENKINS-45024 Use org.eclipse.aether.artifact.Artifact#isSnapshot() to identify snapshot versions

  • JENKINS-40484 Better troubleshooting messages

2.5.0

  • JENKINS-43094 Support Fingerprinting of consumed dependencies

  • JENKINS-44807 Generated artifacts are only fingerprinted as fingerprint.original but not as fingerprint.usage

2.3.1

  • JENKINS-44226 Support junit testDataPublishers
    • Publishing of junit test attachments are enabled by default if the junit-attachments-plugin is installed.
    • Junit test attachments can be disabled using options: [junitPublisher(ignoreAttachments: true)]. Sample:

 

Code Block
languagegroovy
titlejunitPublisher ignore attachments sample
withMaven(
        maven:"maven-3.3.9", 
        mavenSettingsConfig: 'my-maven-settings',
        options: [junitPublisher(ignoreAttachments: true)]) {
            
    sh "mvn clean install"
}
  • JENKINS-44386 Add configuration options to the OpenTasksPublisher
    • Sample

...

languagegroovy
titleopenTasksPublisher options sample

...


How can I reduce the footprint of the database of the Jenkins Pipeline Maven Plugin?

The Jenkins pipeline Maven plugin uses a database to trigger downstream pipelines when a snapshot is built.

For production grade deployments, a MySQL database is needed instead of the embedded H2 database. My SQL 5.6+, Amazon Aurora MySQL and MariaDB 10.2+ have been successfully tested.

To reduce the usage of the database, disable the "Pipeline Graph Publisher" navigating to "Manage Jenkins / Global Tool Configuration / Pipeline Maven Configuration" then clicking on "Add Publisher Options", selecting "Pipeline Graph Publisher" and checking the "disabled" checkbox.

Image Added

Anchor
mavenExecutionInterrupted
mavenExecutionInterrupted

Why do I see messages "[withMaven] One or multiple Maven executions have been ignored..." in the build logs?

The message "[withMaven] One or multiple Maven executions have been ignored by the Jenkins Pipeline Maven Plugin because they have been interrupted before completion..." because one or several Maven execution (e.g. "mvn deploy") have been interrupted before they could gracefully complete.
The event "org.apache.maven.eventspy.EventSpy#close()" has not been invoked on the Maven event spies.
This interruption usually happens because the mvn process has been killed by the Operating System, typically for memory constraints in Docker or cgroups environments. Another cause is a "kill -9" during the build.

Why do I see messages "javax.xml.parsers.FactoryConfigurationError: Provider for class javax.xml.parsers.DocumentBuilderFactory cannot be created"

This error is caused by the installation of another plugin that pulls an outdated version of Apache Xerces. That pulls a version of Apache Xerces that is not compatible with the version of the JVM. Typically, Xerces 2.6 will not be compatible with a JDK 8 due to changes in the JAXP API (sample:

Jira
serverJenkins JIRA
serverIddd058dce-0c66-3b77-8b09-71b1d7728747
keyJENKINS-47486
).

The solution is to get this plugin updated so that it uses a more recent of Xerces that would be compatible with the JDK.

To identify the plugin that is pulling an outdated version of a JAXP implementation (typically Xerces), navigate to the Jenkins Script Console ("Manage Jenkins" then "Script Console") and execute the following groovy script:

Code Block
String className = "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"

Class klass
try {
  klass = Class.forName(className)
} catch (Exception e) {
  println("Exception trying to load " + className + " from the system classloader, try the thread context classloader " + e)
  // contextClassLoader should not work but let's try it.
  klass = Class.forName(className, false, Thread.currentThread().getContextClassLoader())
}

java.security.CodeSource codeSource = klass.getProtectionDomain().getCodeSource()

if (codeSource == null) {
  println(klass.toString() + " -> source not found")
} else {
  println(klass.toString() + " -> " + codeSource.getLocation());
}

The output message will show from which plugin the XercesParser is loaded. Sample with a plugin "my_plugin" that would load an outdated 2.6.2 version of Xerces:

No Format
class org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -> file:/var/lib/jenkins/plugins/my_plugin/WEB-INF/lib/xercesImpl-2.6.2.jar 

How to use Maven build data in generated emails

It is possible to use informations generated by Maven pipelines in emails generated by the Jenkins Email Ext Plugin.

See https://groups.google.com/forum/#!topic/jenkinsci-users/sPAYLh1W1cM

Code Block
languagegroovy
titleSample Pipeline code to expose artifact details in emails
env.DEPLOYEDARTIFACTS = getDeployedArtifacts()

@NonCPS
def getDeployedArtifacts() {
    def deployed = ''
    Collection<org.jenkinsci.plugins.pipeline.maven.MavenArtifact> generatedArtifacts = currentBuild.rawBuild.getAction(org.jenkinsci.plugins.pipeline.maven.publishers.MavenReport.class).getGeneratedArtifacts();
    for (org.jenkinsci.plugins.pipeline.maven.MavenArtifact generatedArtifact:generatedArtifacts) {
    	if (generatedArtifact.isDeployed()) {
    	   
    	    deployed= deployed.concat(generatedArtifact.getUrl())
    	    deployed = deployed.concat("===")
    	    deployed = deployed.concat(generatedArtifact.getShortDescription())
    	    deployed = deployed.concat(",") 
        }

    }
    return deployed
}


In EXT-MAIL-STANDARD-TEMPLATE

Code Block
languagexml
titleSample mail template using Maven build details
    <br />
    <!-- MAVEN ARTIFACTS -->
    <j:set var="mbuilds" value="${it.getAction('org.jenkinsci.plugins.workflow.cps.EnvActionImpl').getOverriddenEnvironment()}" />
        <h5>Deployed Artifacts</h5>
         <j:set var="generatedArtifacts" value="${mbuilds.get('DEPLOYEDArtifacts')}" />

       <table width="100%" style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
        <j:forEach var="artifacts" items="${generatedArtifacts.split(',')}" >
        <j:set var="artifact" value="${artifacts.split('===')}" />
         <tr bgcolor="white" >
sh 'mvn package verify'
}

 

 

2.3.0

  • Add configuration options to disable the publishers. Code look like:

...

languagegroovy
titleOptions to disable publishers

...

       <td class="bg1" colspan="2" style="font-family: Verdana, Helvetica, sans serif; font-size: 120%; color: black">
          <li>
            <a href="${artifact[0]}">
    

...

 

2.2.1

  •  JENKINS-44088 Fix bug when Windows agent use the "/" file separator instead of the "\" file separator

2.2.0

2.1.0

  • JENKINS-39407 - Use Maven Global Settings and Maven Settings defined at the Jenkins global level if not specified in the pipeline withMaven(){...} step

2.0.3

  • JENKINS-43714 - withMaven thinks that "mvn test" generates a jar file causing a FileNotFoundException trying to archive it 

  • JENKINS-43678 - Exception archiving and fingerprinting Maven artifact

  • JENKINS-43616 - Flattened pom throws errors

2.0.2

  • JENKINS-43261 - Bug - withMaven parses emtpy EventSpy logfiles
  • JENKINS-43529 - Bug - Disabled Jenkins Maven Event Spy generates an invalid XML build log file

  • JENKINS-43491 - Enhancement - Feature flag to archive the Maven build logs for troubleshooting purpose (marker file ".archive-jenkins-maven-event-spy-logs")

2.0.1

2.0

  • Detect Maven build details and process the outputs of the build:
  • More detailed traceability of the Maven settings used for the build

0.7

  • High severity security release, please read advisory for SECURITY-309. If you are running 2.0-beta you should update at least to 2.0-beta-6

0.6

  • Wrong release, no changes over the previous.

0.5

  • JENKINS-39916 upgrade to config-file-provider:2.15.1 and support definition of Maven settings file and global settings file at the folder level

0.4

  • JENKINS-39134 -  Fix exception after resuming a build
  • Allow defining global Maven settings by config file (globalMavenSettingsConfig) and by file path (globalMavenSettingsFilePath)
  • JENKINS-40142 - Snippet generator was creating parameters even if they were left empty

0.3

  • JENKINS-38709 - Console log filter was being overriden, which didn't allow the use of other steps which filtered the logs (ie. MaskPasswordBuildWrapper, AnsiColorBuildWrapper, etc.)
  • MAVEN_TERMINATE_CMS is no longer overriden. Setting MAVEN_TERMINATE_CMS to "on" causes Windows batch execution to be completed after the first call to mvn, as mvn will use exit instead of exit /b

0.2

  • First stable release
  • JENKINS-37613 - Unify naming convention for tool installation. The mavenInstallation parameter was renamed to maven.

0.1-beta

  • Initial version
        ${artifact[1]}
          </a>
          </li>
           </td>
         </tr>
         </j:forEach>
       </table>
 <br />


Known Limitations

Maven and JDK installation not supported in docker.image('xxx').inside{...}

Maven and JDK installers do not work with "docker.image('xxx').inside{...}" as the docker step does not allow the use of Tool Installer, the preinstalled Maven and JDK on the docker image will be auto-discovered and used.

withMaven() not supported in "docker.image('xxx').inside{...}" with old versions of the Docker engine

withMaven() not supported in "docker.image('xxx').inside{...}" with old versions of the Docker engine such as Docker 1.13.1 on CentOS7.

Any help to fix this bug is more than welcome.

Jira
serverJenkins JIRA
serverIddd058dce-0c66-3b77-8b09-71b1d7728747
keyJENKINS-40484

Changelog

See https://github.com/jenkinsci/pipeline-maven-plugin/releases