How to use two user defined variables for same thread group for HTTP requests(server name or IP)?

enter image description here

ex: I need run my same j meter scripts in two servers(test, production)

  • Do you mean to say when you run in test use one set of server and and when in production use another? Commented Mar 15, 2017 at 18:31
  • I mean i want to run my test in both servers (server 1,server2) at the same time.
    – lak
    Commented Mar 17, 2017 at 6:37
  • any comments pls?
    – lak
    Commented Mar 20, 2017 at 15:19
  • You can do that with two separate scripts. One sending traffic to test and another to production. The question i have for you is why do you want to run both the tests at the same time? Commented Mar 20, 2017 at 16:31
  • @ Abhishek Asthana actually I want to maintain only one Script... sorry mistakenly typed that 'same time'. I want to run these scripts after run in Test and then Production.This will be run in server automatically once we set up minimum changes need thats why..
    – lak
    Commented Mar 21, 2017 at 13:54

3 Answers 3


In the top level User defined Variables config element declare 1 variable server and assign it a value like ${__P(server,test-server-name)} and when you run your test from command line you can pass the value that you want to use using the -J argument like -Jserver=production-server-name. For test it will be the test server and for production it will be the production server. User Defined Variables You can do something similar for all environment specific variables.

Refer to __property link for details


IMO you are solving the wrong problem. If you have the same JMX file, differing only in what environment (url) it is running against, the script to write is one that generates a jmx file. There are a lot of ways to do this, but I use the ruby lib ruby-jmeter which allows me to generate a jmx file that will run against a specified environment, with a specified number of threads, duration, etc.

This approach gives you far more flexibility and will absolutely save you time in the long run.


You are making it complicated for nothing. Open a text file, put the 2 addresses in 2 lines, as:


Save it as servers.csv file in the same location where your Jmeter's JMX file. Then add a "CSV Data Set Config" element (Add -> Config Element). In the details fill:

Filename: servers.csv
File encoding:
Variable Names: ServerName
Allow quoted data?: False
Recycle on EOF?: True
Stop thread on EOF?: False
Sharing mode: All threads

And now, you can add "HTTP Request Defaults" element and put in the "Web Server" frame -> "Serer Name or IP:" : ${ServerName} Or put in every request the same in "Serer Name or IP:".

In this way, using 2 threads, each of them will have the same variable name but different value.

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.