Due to some maintenance issues, this service has been switched in read-only mode, you can find more information about the why

and how to migrate your plugin documentation in this blogpost

Skip to end of metadata
Go to start of metadata

Jenkins provides a job type dedicated to Maven 2/3. This job type integrates Jenkins deeply with Maven 2/3 and provides the following benefits compared to the more generic free-style software project.

  • Jenkins parses Maven POMs to obtain much of the information needed to do its work. As a result, the amount of configuration is drastically reduced.
  • Jenkins listens to Maven execution and figures out what should be done when on its own. For example, it will automatically record the JUnit report when Maven runs the test phase. Or if you run the javadoc goal, Jenkins will automatically record javadoc.
  • Jenkins automatically creates project dependencies between projects which declare SNAPSHOT dependencies between each other. See below.

Thus mostly you just need to configure SCM information and what goals you'd like to run, and Jenkins will figure out everything else.

TODO

Talk about how maven modules gets represented in sub projects, and how build numbers among sub-projects are controlled. Use some screenshots.

Automatic build chaining from module dependencies

Jenkins reads dependencies of your project from your POM, and if they are also built on Jenkins, triggers are set up in such a way that a new build in one of those dependencies will automatically start a new build of your project. Jenkins understands all kinds of dependencies in POM. Namely,

  • parent POM
  • <dependencies> section of your project
  • <plugins> section of your project
  • <extensions> section of your project
  • <reporting> section of your project

This process takes versions into account, so you can have multiple versions/branches of your project on the same Jenkins and it will correctly determine dependencies. Note that dependency version ranges are not supported, see https://issues.jenkins-ci.org/browse/JENKINS-2787 for the reason.

This feature can be disabled on demand - see configuration option Build whenever a SNAPSHOT dependency is built

Environment Variables (since 2.1)

Maven project type exposes the following environment variables, allowing you to use them as variable expansions in build configuration. The sampe values are the values of the variables if you are building this tree(https://github.com/jenkinsci/jenkins/tree/jenkins-1.536)

Name

Example

Meaning

POM_DISPLAYNAME

Jenkins main module

Taken from <name> in POM

POM_VERSION

1.536

Taken from <version> in POM

POM_GROUPID

org.jenkins-ci.main

Taken from <groupId> in POM

POM_ARTIFACTID

pom

Taken from <artifactId> in POM

POM_PACKAGING

pom

Taken from <packaging> in POM

The Maven Integration Plugin

The Maven 2 project type is contained in the Maven Integration plugin, which is bundled with Jenkins. If you are running any version of Jenkins earlier than the current release, it may show up in the list of plugins having available updates. It is recommended not to upgrade the Maven Integration plugin separately from Jenkins itself. While it is technically a plugin, it is developed, tested, and released as part of the Jenkins core.

Maven Surefire Test Results

The Maven Integration plugin understands the POM and knows about specific Maven testing plug-ins, such as org.apache.maven.plugins:maven-surefire-plugin, org.eclipse.tycho:tycho-surefire-plugin, etc. The definitive list of supported test plug-ins can be found at https://github.com/jenkinsci/maven-plugin/blob/master/src/main/java/hudson/maven/reporters/TestMojo.java. For such known test plug-ins the Maven Integration plugin is able to collect test results from their default or POM-configured reports directory. Test results from Maven test-capable plug-ins unknown to the Maven Integration plugin can be collected if their execution goal is 'test', 'test-run', 'integration-test' and they have a 'reportsDirectory' configuration property containing the location of their test results. Other than that results from unknown test plug-ins (such as org.codehaus.mojo:exec-maven-plugin) will not be collected, even if they are returned in the configured test results location (default target/surefire-reports).

Collecting Test Results from arbitrary test plugins

As of org.jenkins-ci.main:maven-plugin:2.13, there is a mechanism to inform the Maven Integration plugin of the location of test results produced by an unknown Maven test plug-in. If the POM declares a property with a name matching the pattern 'jenkins.<plugin-execution-id>.reportsDirectory', where <plugin-execution-id> is the unknown test plug-in's execution identifier, the Maven Integration plugin will resolve the value of this property against the project base directory and collect any test results that it finds in the resulting directory.

Example

In order to have Jenkins pick up the test results produced by an unknown plugin with a plugin execution ID 'e2eTests' which generates JUnit-compatible XML reports in the directory 'target/protractor-reports' in the project workspace, add the following property to your project POM:

<properties>
    <jenkins.e2eTests.reportsDirectory>target/protractor-reports</jenkins.e2eTests.reportsDirectory>
</properties>

15 Comments

  1. Unknown User (cteo)

    I have a project that has this setup in a project
    parent POM
    Module 1

    • <dependencies> section of your project
    • <extensions> section of your project
    • <reporting> section of your project
      Module 2
    • <dependencies> section of your project
    • <extensions> section of your project
    • <reporting> section of your project
      Module 3
    • <dependencies> section of your project
    • <extensions> section of your project
    • <reporting> section of your project

    Each module creates its own reporting section. However Hudson only display the reporting section in the Module 1. Module 2 and 3 are not accessible.

    Is there any way to get Hudson to display all 3?

    Thanks!

    1. Unknown User (gaston g)

      Hi Carolyn,

      I've the same structure but I'm not able to build anything... it keeps saying that there is a missing dependency... can you add some example of your parent pom and at least one module pom ?

      I'm using Eclipse Galileo, M2 plugin to create parent projects and modules...

      Thanks in advance

      GASTON

  2. Unknown User (tpijl)

    If a maven2 job is triggered by SCM it logs in with user "anonymous". When solving dependencies it uses a local repository.

    Where is that located in this case? And if I have a specific settings.xml where should I place this in this case

    I use Javawrapper to start my Hudson as a daemon on an OpenSuse 10.3 Linux server.

  3. Unknown User (mmorizot)

    hi,

    I was wondering if there was a way of trigerring the reloading of a pom file by hudson?

    the idea behind this is to modify in my workspace, the pom files (pre-build task) and then ask hudson to consider my newly modified pom, and not the initial one.

    I'm trying to implement a release process (without using release:*).

  4. Unknown User (bombjack)

    Hello everyone.
    We have a problem with Hudson and maven

    .
    We want to use Hudson outsourcing all configuration files (hudson_home) on another server.
    We configured the hudson_home in web.xml:
    \\ServerName\hudson

    When Hudson starts, it created all the files on the server. Therefore, the address is correct.
    But when will perform an initial build (maven in our case), it no longer works. Hudson displays the following message:

    OutputConsole
    trunk $ \\pcdsi547\int-continue\jdk\jdk1.5.0_07/bin/java -Xmx1024m -XX:MaxPermSize=256m -cp D:int-continue\hudson\plugins\maven-plugin\WEB-INF\lib\maven-agent-1.358.jar;\\pcdsi547\int-continue\maven\boot\classworlds-1.1.jar hudson.maven.agent.Main \\pcdsi547\int-continue\maven D:\P747\tomcat\tomcat-6-su\webapps\hudson\WEB-INF\lib\remoting-1.358.jar D:int-continue\hudson\plugins\maven-plugin\WEB-INF\lib\maven-interceptor-1.358.jar 3522 D:\int-continue\hudson\plugins\maven-plugin\WEB-INF\lib\maven2.1-interceptor-1.2.jar
    java.lang.NoClassDefFoundError: hudson/maven/agent/Main
    Exception in thread "main" ERROR: Failed to launch Maven. Exit code = 1 Finished: FAILURE

    It was noticed in the console output, it replaces some jars network address
    MyServer with D:\ (the letter is located where the application server).
    There is more then some jars (whose address is changed). We should not have D:\ *** but all the time
    pcdsi547****.
    What do you think? Did you encounter this error?
    We tested on Tomcat and Weblo (and therefore jdk and jrockit), we get the same error.

    edit: it works on a Windows environment I think the problem is adress UNC.

  5. Unknown User (nathan.bragg@otda.state.ny.us)

      I can't figure out when I'm running a Maven build using Hudson it would hang on 'Parsing POMs' however when I set up the project for freestyle it builds correctly.  What could possibly be different between how the two are set up that is causing my Hudson Server to not get past 'Parsing POMs'?

    Any ideas?

  6. Unknown User (dhordey)

    I am using maven 2/3 type pf project. But when it tries to build maven does not receives any property values from the job configuration and profiles i am using does not get activated

    When set goals like " -Denv=dev1 deploy " maven receives env property and associated profile gets set.

    But when i use job parameter named "env" and goals set to just "deploy" , maven do not get env variable set and the build fails parsing POMs   

    Please advise

  7. Unknown User (sodul)

    I'm having an issue on my master where the artifacts retention policy does not seem to be applied the sub-modules. I have a job with a very short retention policy (Discard Old Builds: keep 10 builds max, 10 artifacts max). On the jenkins UI this is respected for the job itself, but the 'modules' kept on growing, eventually almost filling up my master's disk.

    By modules, I mean under the jobs directory on the master:

    jobs/some-job-name/modules/com.company$modulename/builds/

    Any idea what is happening? Interestingly I can reach the url for the modules and there is even a /config url for it but the 'Discard Old Builds' checkbox is not present there.

    I could write a script the would scan all the jenkins jobs on the master, read the retention policy from config.xml and then apply it to the modules, but Jenkins should have taken care of that.

    1. Unknown User (empinchen)

  8. Unknown User (zubactik)

    Hi All!

    Can I setup Jenkins to launch Maven task vis javaw instead of java?

  9. Unknown User (rop)

    In the Jenkins maven-build config-page, there is an option: "Maven Validation Level".

    Is there documentation for this anywhere?

    What does the avaliable options mean exactly?

  10. Unknown User (xjg6yzl)

    Are there any plans by anyone to fix this issue with the maven plugin?

    https://issues.jenkins-ci.org/browse/JENKINS-19352

    The whole idea behind using Jenkins is for continuous integration where you know right away when someone commits something to SCM that breaks your project. If the maven plugin fails the job but doesn't tell you what broke, its somewhat close to being useless.

  11. Unknown User (jadar)

    Anyone know why my Maven environment variables aren't being set? I'm trying to access them from a post-build script but they're not set.

    1. Unknown User (ljanzik)

      any news on this comment? the variables are not being set.

      1. Unknown User (dlethin)

        I'm experiencing this too -- I don't see any environment variables prefixed with POM_

        Thanks.

        Doug