Jenkins: Pass multiple MAVEN profiles via user selection - maven

following situation: I want to build a maven project via jenkins and also be able to select multiple maven profiles (to be precise it has to build with two profiles, one of those is a fixed value called 'dev', so basically I want to be able to select the second profile from a list of profiles) before building, so a parameterized build. I add the selectable profile as a option-list and now I'm able to select it from a dropdown, so far, so good.
BUT: It seems the problem is the multiple profile part.
In the maven goal-field I type
clean install -Pdev,$Client
with 'Client' being the parameter for the build which contains the selected value.
But if I start the build, the command line says e.g.
mvn clean install "-Pdev,test"
with the problem being it wrapping the Profiles in apostrophes. If I test it with a single parameter it works as expected:
clean install -P$Client

Based on the following explanation, try some of these:
#1 mvn install -P profile1,profile2
#2 mvn install -Pprofile1 -Pprofile2
#3 mvn install -P 'profile1,profile2'
Explanation
According to official documentation
https://maven.apache.org/guides/introduction/introduction-to-profiles.html
The correct multi profile invocation is :
mvn groupId:artifactId:goal -P profile1,profile2
And some variations are allowed:
https://stackoverflow.com/a/16792775/3957754
https://stackoverflow.com/a/42766252/3957754
mvn install -Pprofile1 -Pprofile2
Ans as always :s an special treatment for windows:
mvn install -P 'profile1,profile2'

Related

Run mvn command on module from existing source

I imported several maven modules on IntelliJ IDEA by using the option File/New/Module From Existing Source. This is working fine but I'm not able to run mvn command lines on one specific module by its module name.
I was able to do it by specifying the path to the pom.xml file by using -f option:
mvn -f "path/to/pom.xml" clean
But I would like to avoid having specifying the path every time I want to run a mvn command. Is their any way to run the command by specifiying the name of the module ?
Thank you.
If you use "Run Anything" then it's possible to select module at the top right corner
You can perform maven install, maven clean etc for a complete module or sub modules of a project using top right option in IntelliJ.
Maven-->select module/submodule folder-->Plugins-->select the option:- deploy, compile, install, clean etc.

Maven project execute without ide

I do a selenium test using Maven. I have more than 20 test classes. How do I export and run them without ide ?
I am also using the POM structure.
Simply open terminal/cmd, navigate to you project directory and use maven command:
mvn clean test
clean — delete target directory
test — run tests
If you want to specify which exactly class you want to run (no all like above) you can run a -Dtest parameter like suggested:
mvn clean -Dtest=testClass install
First navigate to folder where your project's pom.xml is located.
cd DirectoryWherePOMisLocated
then execute below command,
mvn clean -Dtest=classNameWhichYouWantToExecute install
If you want to execute multiple classes just separate them with , in -Dtest argument.
Hope this helps!!

Set up Jenkins to run a specific maven command

I’m new to Jenkins and currently working on a maven project.
I am able to run a simple Jenkins job using maven commands.
mvn clean install
However, the extended requirement requires me to us an additional parameter in the maven command
mvn clean install -DfileName=file1
Is it possible to have a drop down with file names (e.g. file1, file2 ..) and have the user selected one append to the maven command.
mvn clean install -DfileName = {selected filename from dropdown}.
Could some one please assist with this along with what plugin and how can I setup.
Parameterize your jenkins job see https://wiki.jenkins.io/plugins/servlet/mobile?contentId=34930782#content/view/34930782.
Use choice parameter to add your file name choices
Active Choices Plugin - https://wiki.jenkins.io/display/JENKINS/Active+Choices+Plugin
The user selected choice can be used in your maven command using "{params.param_name}".

What is the meaning of clean test -P?

For one of the project, we are supporting I see the Maven
clean test -P DEV,CI
inside the Goals and Options for the build option of Jenkins. Its is causing the Sonar analysis of the test jobs behave incorrectly.
I tried to find the meaning of -P option, but did not get any solutions so far.
The Maven CLI Options Reference documents what -P means:
-P,--activate-profiles <arg> Comma-delimited list of profiles to activate
It is related to profiles. Read more at Introduction to Build Profiles.

Skip tests in Jenkins

I've set up a build on Jenkins for a Maven project, and I would like to build it without running any of the tests. I've tried entering "clean install -DskipTests" in the goals field, like this:
But it doesn't work. What am I doing incorrectly?
Note: I want to skip the tests without touching the pom. I have a separate build that DOES run the tests.
The problem is that I omitted =true. I was able to build without running tests by entering:
clean install -DskipTests=true
Just to extend the answer, maven has 2 options for skipping tests:
-DskipTests=true — The one that was mentioned. With this parameter, maven ignores tests completely.
-Dmaven.test.skip=true — With this option maven compiles the tests but doesn't launch them.
So you may want to use the second option instead as fast code compile validation. E.G.: if you develop some library or module that will be used by some one else you must be sure that you don't brake contract with the client. Tests compilation can help you with this.
Use either of these parameters depending on your needs.
use "Goals and options" value is "clean install -DskipTests=true".
it works like a Charm. I saved hours of time using this Option. :-)
I use option "-DskipTests=true" in "Invoke top-level Maven target" -> "JVM Options" and it works fine.

Resources