44

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?

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
GeorgeFabian
  • 461
  • 1
  • 4
  • 3

4 Answers4

79

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)}

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
Refael
  • 1,252
  • 9
  • 10
14
  1. Open the Jmeter file (jmx) in Jmeter GUI and add parameters as in this screenshot:

enter image description here Click on Save button.

  1. Now, run the command with these parameters, for example:

     jmeter -t TestPlan.jmx -Jthreads=10 -Jcount=50 -Jrumpup=5 
    
Gavriel Cohen
  • 4,355
  • 34
  • 39
11

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

olyv
  • 3,699
  • 5
  • 37
  • 67
5

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)}
Bilal Demir
  • 587
  • 6
  • 17