Reputation: 471
I'm trying to automate some perf testing. I'd to pass server locations into a generic jmx from a Jenkins job. I'd like to be able to do something like:
jmeter -n -t foo.jmx -JtestingIP=IP
and have foo.jmx pick up testingIP
.
What is the proper way to do this? When I run that jmeter command, it says that the variable has been stored, but inserting either ${testingIP}
or ${\_\_P(testingIP,)}
into the jmx results in ${testingIP}
or ${\_\_P(testingIP,)}
to be interpreted as just a string.
What am I doing wrong/not doing at all? Is this even possible?
Upvotes: 45
Views: 71797
Reputation: 4623
Now, run the command with these parameters, for example:
jmeter -t TestPlan.jmx -Jthreads=10 -Jcount=50 -Jrumpup=5
Upvotes: 14
Reputation: 686
You have two options to send parameters to jmeter.
First: Sets a system property value.
-Dproperty=value
If value is a string that contains spaces, then you must enclose the string in double quotation marks.
Example:
java -Dmydir="some string" -jar ApacheJmeter.jar -n -t PerformanceTest.jmx
Reading parameters in jsr223 beanshell:
log.info("mydir:" + System.getProperty("mydir"));
Reading parameters in request sampler with Bean Shell function:
${__BeanShell(System.getProperty("mydir"))}
Second: Defines a local JMeter property
-J[prop_name]=[value]
Example:
jmeter -n -t PerformanceTest.jmx -Jmyparamter=4 -Jduration=300
Reading properties in request sampler with Bean Shell function:
${__P(duration)}
Upvotes: 5
Reputation: 1282
All you need to do is start your JMeter from the command line (or shell) with the -J option. For example :
-JTestIP=10.0.0.1
And in your script, to get the value, just use function _P:
Example:
${__P(TestIP)}
That should do it.
Note you should put a default value in case you run the script without passing that JMeter property like:
${__P(TestIP,1.1.1.1)}
Upvotes: 82
Reputation: 3817
Take a look at this link http://mkbansal.wordpress.com/2012/08/01/jmeter-command-line-script-execution-with-arguments/. Also I would try to specify default value, like ${__P(testingFromCommandLineIP,defaultIP)}
where testingFromCommandLineIP
-- argument you specify when running test plan from command line, defaultIP
-- default value
Upvotes: 11