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!

asked Oct 1, 2018 at 13:32

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

answered Oct 1, 2018 at 14:41
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

answered Jul 12, 2021 at 23:06
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

answered Jul 24, 2024 at 12:37
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." Commented Jul 24, 2024 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. Commented Jul 25, 2024 at 13:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.