Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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?

question from:https://stackoverflow.com/questions/19823954/jmeter-pass-command-line-variables-into-a-jmx

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...