Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jmeter pass command line variables into a jmx

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?

like image 296
GeorgeFabian Avatar asked Nov 06 '13 22:11

GeorgeFabian


People also ask

How does JMeter pass properties?

Properties are passed using the -J option to the jmeter start as stated earlier. But there is a drawback with properties. Properties cannot be set easily within JMeter itself. You have to resort to beanshell expressions to change them.

What is __ P in JMeter?

Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function. When using \ before a variable for a windows path for example C:\test\${test}, ensure you escape the \ otherwise JMeter will not interpret the variable, example: C:\\test\\${test}.

What is CLI mode in JMeter?

Using CLI mode, you can generate a CSV (or XML) file containing results and have JMeter generate an HTML report at end of Load Test. JMeter will by default provide a summary of load test while it's running. You can also have real-time results during your test using Backend Listener.


1 Answers

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:

  • http://jmeter.apache.org/usermanual/functions.html#__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)}

like image 122
Refael Avatar answered Oct 08 '22 00:10

Refael