I saw bits and pieces of information all over the internet about parameters and properties and command-line arguments, but what I was looking for I didn’t find: a simple, straightforward explanation of how to use a Paramaterized Build in Jenkins to pass arguments through to the jUnit tests that run the functional tests that I’ve built on Webdriver. So: here it is!
Step 1: Command-line via Maven to jUnit
Use the System.getProperty tor ead system properties in Java:
remoteHost = System.getProperty("remoteHost"); if (remoteHost == null) remoteHost = "http://localhost:4444/wd/hub"; browserName = System.getProperty("browserName"); if (browserName == null) browserName = "Internet Explorer";
And use -D to pass them with Maven:
mvn test -DbrowserName=Firefox
Voila!
Step 2: Jenkins to Maven
First make the build a paramaterized build:
Then adjust the maven build step as shown:
(Quotes are important here because of Internet Explorer)
Voila!
Hi!
May be you can help me with suggest issue.
Few times i search solution about System.getProperty there used in https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin or https://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin.
My issue is take downstream Jenkins job some environment variables.
I use pre build `choise parameter`, there named GOAL.
After that define build flow using flow DSL like this:
t = System.getProperty(‘GOAL’)
println t
/ /build(“my downstream_job”, target: t)
output of println function is `null`, but `choise parameter` was defined before start build.
Thanks! And excuse for bad English.
You missed a step: when you invoke Maven, you need to pass the parameter in the command-line. Should be something like “-DGoal=$GOAL”. See step two of the blog post for a screenshot.
Yes, it’s not mistake — i don’t use ant or maven.
My goal only give environment variable to downstream job.
After that this value will use in shell script. That’s all. =)
I think you had experience in Groovy DSL using. =)
No, I’ve never used Groovy. Sorry 🙂
OK, however thank you.)
If i’ll find solution, wright it here.)
It’s so simple.
For use pre build params in downstream job’s we should use this construction.
println params; \\ show all pre build parameters in map form: [ENVVAR:value]
t = params.ENVVAR;
build(“Our_downstream_Job”, target: t)
=)
This is very useful. Thank you!
Saved my day! Thank you very much 🙂
Hi.
How can I do the same, but not for code – but for pom.xml
For example: I have in pom.xml
???????.xml
And I have 10 different “testng.xml” in Project.
So I’d like to pass the name of “testng.xml” to pom.xml to execute particular “testng.xml”.
Thanks!
configuration
suiteXmlFiles
suiteXmlFile — ????????????.xml — suiteXmlFile
suiteXmlFiles
configuration
I believe that you want to look at environment variables for this? Like, reading the environment variables inside your pom.xml? I’m not 100% sure I understand your question correctly, but that might help you find what you need.
Thank you! I was trying to pass in which environment Maven should deploy to and your post connected the dots between JVM variables to Jenkins variables to Maven Variables.
Hi,
I am trying to define and use an environment variable in Jenkins -> Manage Jenkins -> Configure System -> Global properties .
I have a maven project that needs to access the variable defined here.
Can you please share some information about how can I do it?
Awesome! Exactly what I needed. Many thanks 🙂
thanks for the article! its precise and clear 🙂
Also try to not to use dashes ‘-‘ in parameter names in Jenkins, because it might not be passed to maven. https://issues.jenkins-ci.org/browse/JENKINS-32435
Super simple.
Thanks!
Thank you for sharing!
It works even without D key, just like this
“clean test”
And test run in standalone Selenium container:
“docker run –rm -d -p 4444:4444 –name=firefox –network=mynetwork selenium/standalone-firefox”
very nice Thanks
Thanks for this tip! It helped me with my Maven project.
Thanks ssssssssso much! I can run successfully
Hello Bay and thank you for this page! As you say, this straightforward how-to is nowhere else to be found on the internet.
soooo good.
did you have to make any changes in pom.xml so for example System.getProperty(“Url”) would be read in Jenkins
hi,
I am unable to run single testcase
maven
HPALM
Jenkins
mvn clean test -Dtest=$testname -DExecuteFromAPALM=$ExecuteFromHPALM
but not working
when i di same from cmd prompt : mvn clean test -Dtest=$testname -DExecuteFromAPALM=$ExecuteFromHPALM
it worked
Super useful, thank you!! Sometimes the easiest bits of information are the hardest to find – luckily Google ranked your article as No. 1 for the search “how to parameterize a jenkins maven project” which made my life easier.
I used your hint, and hoping that the string for the parameter is not case-sensitive 🙂
Happy Testing!!
Hello,
Can i pass jenkins parameter into pom.xml file? if yes then how?
Hi,
I am trying to pass the value of parameter to maven build command in jenkins pipeline using groovy script but the command is not treating the value of the variable, rather its taking that variable as value. PFB example:
jenkins parameter name – Environment
stage (build)
bat ‘mvn clean install -Denvironment=$Environment
Hi Bay I have to pass three Stringparameter inside a method and execute an orchestration in my maven project . The code is written in Java rest assured framework . How to pass this three parameter from Jenkins . Please help