One of the great things about Maven is that it provides a standard project and build layout, along with a standard set of “goals.” Not only does this make it easier for developers to get up to speed on a new project, but it also allows Jenkins to provide special support for Maven projects, reducing the configuration needed while enhancing the build report automatically. That is the goal of the Maven plugin for Jenkins.
The central feature of the Maven plugin for Jenkins is the Maven 2/3 project type. Thanks to the Maven project object model (POM), this project type can automatically provide the following features:
- Archive artifacts produced by a build
- Publish test results
- Trigger jobs for projects which are downstream dependencies
- Deploy your artifacts to a Maven repository
- Breakout test results by module
- Optionally rebuild only changed modules, speeding your builds
All of the above can be accomplished in Free style builds, but this requires more configuration on your part.
Requirements for Plugin Use
All Jenkins releases have the Maven plugin included. You must also have at least one Maven installation.
How to Use It
First, you must configure a Maven installation (this step can be skipped if you are using DEV@cloud). This can be done by going to the system configuration screen (Manage Jenkins-> Configure System). In the “Maven Installations” section, 1) click the Add button, 2) give it a name such as “Maven 3.0.3” and then 3) choose the version from the drop down.
You will then be presented with the job configuration screen. On this page, you need to provide 1) the SCM and 2) the Maven goals to call. That’s it! Choose the SCM you want to use (we’ll use Git), and then specify what Maven targets to call. We’ll call the “clean site install” goals so we can see the full effect.
Now, just click build now, and click on the progress bar in the left hand “Build Executor Status” to watch Jenkins install Maven, checkout your project, and build it using Maven. The build output should look something like this:
Now that the project is built, we can navigate to the detail page for our Maven module (project page -> Modules link on the left). For each module, Jenkins displays:
- A link to the module’s workspace
- The module’s artifacts
- A clickable test result trend
- Recent changes (just for that module!)
Finally, if we had configured Jenkins to build any downstream dependencies of this project, they would automatically start building after this build completed.
If you are using the Maven plugin, you should also investigate the M2 Release Plugin for automating releases with one click. The M2 Extra Steps plugin will let you run arbitrary build steps before and after your build. Finally, the new Config File Provider plugin lets you maintain different settings.xml which can be referenced by your Maven builds.
Maven is a trademark of the Apache Software Foundation.
Want to learn the latest in Jenkins? Subscribe to the Jenkins newsletter, Continuous Information. This monthly newsletter contains all of the latest interesting and useful happenings in the Jenkins community, sent directly to your inbox.