通过cmd运行 jmeter -? 可以得到所有命令行选项(本文最后)
其中可以看到下面 -J 的使用
-J, --jmeterproperty <argument>=<value>
Define additional JMeter properties
当通过JMeter属性的方法调用变量时,需要修改变量的传入方式。普通的定义变量是:${threadsUsers}的形式。
但是本方法是通过添加JMeter的属性,属性和参数是不同的,因此在调用中采用${__P(threadsUsers)}的形式进行调用。(注意是两个下划线)
这样就可以完成通过命令行的参数,来达到更改脚本中变量的效果了!
jmx文件中的设置:
${__P(threadsUsers,5)} 并设置默认值
Jenkins(Excute Windows batch command)
jmeter -n -t %TestAPI%.jmx -JthreadsUsers=%threadsUsers% -JDuration=%Duration% -l result_output\%TestAPI%.jtl
所有命令行选项:
--? print command line options and exit -h, --help print usage information and exit -v, --version print the version information and exit -p, --propfile <argument> the jmeter property file to use -q, --addprop <argument> additional JMeter property file(s) -t, --testfile <argument> the jmeter test(.jmx) file to run -l, --logfile <argument> the file to log samples to -i, --jmeterlogconf <argument> jmeter logging configuration file (log4j2.xml) -j, --jmeterlogfile <argument> jmeter run log file (jmeter.log) -n, --nongui run JMeter in nongui mode -s, --server run the JMeter server -H, --proxyHost <argument> Set a proxy server for JMeter to use -P, --proxyPort <argument> Set proxy server port for JMeter to use -N, --nonProxyHosts <argument> Set nonproxy host list (e.g. *.apache.org|localhost) -u, --username <argument> Set username for proxy server that JMeter is to use -a, --password <argument> Set password for proxy server that JMeter is to use -J, --jmeterproperty <argument>=<value> Define additional JMeter properties -G, --globalproperty <argument>=<value> Define Global properties (sent to servers) e.g. -Gport=123 or -Gglobal.properties -D, --systemproperty <argument>=<value> Define additional system properties -S, --systemPropertyFile <argument> additional system property file(s) -f, --forceDeleteResultFile force delete existing results files before start the test -L, --loglevel <argument>=<value> [category=]level e.g. jorphan=INFO, jmeter.util=DEBUG or com.example.foo=WARN -r, --runremote Start remote servers (as defined in remote_hosts) -R, --remotestart <argument> Start these remote servers (overrides remote_hosts) -d, --homedir <argument> the jmeter home directory to use -X, --remoteexit Exit the remote servers at end of test (non-GUI) -g, --reportonly <argument> generate report dashboard only, from a test results file -e, --reportatendofloadtests generate report dashboard after load test -o, --reportoutputfolder <argument> output folder for report dashboard