简体   繁体   中英

JMeter: more than nine parameters from Jenkins

I am trying to pass more than nine parameters from Jenkins to JMeter4.0. As I was reading, I found out that JMeter does not accept more than 9 parameters. As a workaround, I want to pass all the parameters as a string and split it in JMeter BeanShell.

java -jar -Xms512m -Xmx2048m C:\JMeter4\bin\ApacheJMeter.jar -Jjmeter.save.saveservice.output_format=csv -Jjenkinsparams="%Timetorun%,%Users%" -n -t %JMeterPath%\bin\tests\tests.jmx -l %WORKSPACE%\Results.csv

The tests run on a Windows machine. From this call I have jenkinsparams = "300,2"

I use a BeanShell PreProcessor like this:

String line = "${__P(jenkinsparams)}";
String[] words = line.split(",");
vars.put("timetorun",words[0]);
vars.put("users",words[1]);
log.info(words[1]);
log.info(users);

I tried few log.info to check the values. For words[1] I have the correct value sent from Jenkins: 2 . For the users the value displayed is: void . I am trying to use it for Number of Threads as: ${__P(users,1)} .

What am I doing wrong? The values clearly arrive from Jenkins but I have a problem passing it to my variable. Thank you

You don't have a script variable named users , so you should either log words[0] :

log.info(words[0]); 

Or you can log the value of JMeter variable called users:

log.info(vars.get("users"));

Or you can assign words[0] to variable called users :

String users = words[0];
log.info(users);

Also you are saving it as variable, not property, so you can retrieve it elsewhere in script as

${users}

The syntax __P refers to property, so if you want to use it as property, you need to change how you are saving it:

props.put("users", words[1]); 

If you do that, ${__P(users,1)} should work

Now, if you want to use this value as number of threads, then you need to do this:

  1. Have Setup thread group with 1 thread, and your script
  2. In the script you must save users as property, otherwise it won't pass between threads
  3. Next thread group then can use it as number of threads

As long as your command line fits into 8191 characters it should not be a problem to pass as many arguments to JMeter as you want, here is an evidence from Debug Sampler and View Results Tree listener combination

JMeter 12参数

So keep calm and pass as many parameters as needed via -J command line arguments.


Be aware that starting from JMeter version 3.1 users are recommended to use JSR223 Test Elements and Groovy language instead of Beanshell so going forward please consider switching to Groovy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM