0

I was following blazemeter tutorial on how to run Jmeter script from the command line (cmd.exe in Windows10 OS). I'm trying to pass environment variable to the Jmeter ${__env} (according to this page) custom function, using Jmeter script from the command line. Below is the screenshot of the env function in Jmeter UI

with quotes

I've also tried without quotes ${__env(password)} and also using JSR223 PreProcessor

vars.put("password",${__env(password)}); 

but that didn't work either.

Below is my command line

set password=MyPassword123
jmeter -n -t C:\Work\Jmeter\MyScript.jmx

But Jmeter fails to execute my test plan

Creating summariser <summary>
Created the tree successfully using C:\Work\Jmeter\MyScript.jmx
Starting the test @ Fri Sep 28 16:45:38 EDT 2018 (1538167538606)
Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
summary =      2 in 00:00:01 =    3.1/s Avg:   250 Min:     1 Max:   499 Err:     1 (50.00%)
Tidying up ...    @ Fri Sep 28 16:45:39 EDT 2018 (1538167539431)
... end of run

Is it possible to read environment variable using Jmeter? How to properly set it up. Has anyone able to achieve this before? Thanks a lot people!

1
  1. When you use User Defined Variables remove the quotation marks around "password", to wit:

    ${__env(password,,) 
    
  2. When you use JSR223 Elements don't inline the function into the script body, either go for "Parameters" section or use code-based equivalent instead like:

    vars.put("password", System.getenv("password"))
    

    This is a form of "soft requirement" because JMeter Functions and Variables syntax conflicts with GString Templates. Moreover it makes Groovy script compilation caching impossible negatively impacting the performance. Check out Apache Groovy - Why and How You Should Use It article for more information regarding using Groovy scripting in JMeter tests

Demo:

JMeter Env Function Groovy

  • Thanks a lot Dmitri, I'll test it later and update with the results! – Tired Of Testing Oct 1 '18 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.