JMeter: more than nine parameters from Jenkins

拜拜、爱过 提交于 2019-12-24 08:47:47

问题


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


回答1:


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

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.




回答2:


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


来源:https://stackoverflow.com/questions/51987207/jmeter-more-than-nine-parameters-from-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!