Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure my Maven Jenkins job to only build modules where I've checked in code?

Tags:

I'm using Maven 3.5, Git, and Jenkins 2.138.1. I have a Maven Jenkins job set up for my multi-module Maven project. Normally, if I want to build just a single module in Maven and whatever it affects, I can run

mvn install -pl myModule -am

from a command line. What I would like to do is configure my Jenkins job to only build the affected Maven modules and their dependencies if someone checks in code for a specific module, thus speeding up my build. How can I configure this in Jenkins?

like image 761
Dave Avatar asked Nov 29 '18 18:11

Dave


People also ask

Where do you need to specify the Maven configuration in Jenkins?

In the Jenkins dashboard (Home screen), click Manage Jenkins from the left-hand side menu. Then, click on 'Configure System' from the right hand side. In the Configure system screen, scroll down till you see the Maven section and then click on the 'Add Maven' button.


1 Answers

If your using a FreeStyle Porject:
you will need to install Maven Project Plugin
Then there is an option "Incremental build-only Build changed modules"

enter image description here

As it states The SCM will handle which modules have been modified and will build only those modules.

In case of Pipeline then the above command as mentioned by you can be used. i.e.

 mvn install -pl myModule -am

The issue is knowing which modules to build when a check-in happens

mvn install -amd -pl $(git status | grep -E "modified:|deleted:|added:" | awk '{print $2}' | cut -f1 -d"/")

The above command should work.

IF you are up to modifying the pom.xml
You will need Maven Incremental Plugin

The below URL gives a detailed explanation on how to achieve this using maven: Jenkins building a product consisting of many Maven projects? (with Jenkins Pipeline plugin?)

Hope it helps :)

like image 150
rohit thomas Avatar answered Sep 25 '22 23:09

rohit thomas