According to JSR223
Sampler
documentation:
JMeter processes function and variable references before passing the script
field to the interpreter, so the references will only be resolved once.
Variable and function references in script files will be passed verbatim to
the interpreter, which is likely to cause a syntax error. In order to use
runtime variables, please use the appropriate props methods, e.g.props.get("START.HMS");props.put("PROP1","1234");
So amend the last line of your script to look like:
log.info(vars.get('counter'))Demo:
还请注意,它使用起来容易得多:
- Counter test element or __counter() function, check out How to Use a Counter in a JMeter Test article for more details
- 循环控制器公开
${__jm__Loop Controller__idx}JMeter变量,该变量保存当前迭代次数



