1

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!

3 Answers 3

2
  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

1
  • Thanks a lot Dmitri, I'll test it later and update with the results! Commented Oct 1, 2018 at 14:47
0

Make sure you installed the Custom Functions Plugin in JMeter Plugins Manager. env function is part of this plugin.

enter image description here

0

more details can be found here

https://techcommunity.microsoft.com/t5/microsoft-learn/automation-of-load-testing-jmeter-script-using-azure-devops/m-p/4199613/thread-id/7825

Automation of load testing (JMeter script) using Azure DevOps release Pipeline (Continuous testing) - using variable manager

2
  • 1
    Welcome to the community. Please review sqa.stackexchange.com/help/how-to-answer, specifically: "Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the external resource is unreachable or goes permanently offline. Links to other websites should always be helpful, but avoid making it necessary to click on them as much as possible."
    – Lee Jensen
    Commented Jul 24 at 17:57
  • I don't think this adds anything to a 5+ year old question with an already accepted answer. Also, this isn't my area of expertise, but I'm not even sure if it answers the question and could well be spam (or at least mistaken for spam). I'd suggest you edit your post to concisely answer the question, and incorporate Lee's suggestion... otherwise, it'll likely get deleted.
    – dvniel
    Commented Jul 25 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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