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?
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.
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"
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With