Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven and Jenkinsfile - skipping previous phases

Tags:

maven

jenkins

I'm exploring Jenkins staging functionality and I want to devise a fast and lean setup.

Basically, Jenkins promotes the use of stages to partition in the build process and provide nice visual feedback about the progress of the build.

So the Jenkinsfile goes something like

stage("Build")
bat("mvn compile")

stage("Test")
bat("mvn test")

stage("Deploy")
bat("mvn deploy")

This works well, but feels wrong, because deploy and test will both do activities from previous phases again.

As a result, in this setup I am building three times (although skipping compilation due to no changes) and testing two times (in the test and the deploy runs).

When I google around I can find various switches and one of them works for skipping unit tests, but the compilation and dependency resolution steps happen regardless of what I do.

Do I need to choose between speed and stages in this case or can I have both?

I mean:

stage("Resolve dependencies, build, test and deploy")
bat("mvn deploy")

is by far the fastest approach, but it doesn't produce a nice progress table in Jenkins.

like image 258
Niels B. Avatar asked Nov 08 '22 18:11

Niels B.


1 Answers

In order to bring incremental builds in Maven phases as Gradle does, you can use takari-lifecycle maven plugin.

So, once the plugin is apply you will get all the benefits. In your example, Test stage which will perform mvn test will avoid compilation because it was compiled in the previous stage and Deploy stage will avoid compilation from your main source code and test source code but tests will be executed again so I suggest to add -DskipTests.

like image 69
Eddú Meléndez Avatar answered Nov 15 '22 07:11

Eddú Meléndez