I have a simple representative jmeter script pictured below but in reality my real script is much more complex. Im using the latest jmeter version. I want to be able to choose a User Defined Variables script conditionally. If I set ENV variable in env_switch to local, test, or stage the result for SELECTED_ENV should match. What I observe though when I run the test (last screenshot):
- only the Debug Sampler (test) runs proving that my if controllers are working correctly. If stage ran I would see Debug Sampler (stage) in the results tree
- SELECTED_ENV is incorrectly set to stage at the end. It proves that even though the stage IF controller evaluates to false - jmeter still runs the user defined variable under the stage IF controller (wtf)
So it seems that even though only one of the if branches runs jmeter still evaluates all user defined variable regardless of where they are placed in the tree. The last one that runs seems to be selected. Experimentally if I place the local controller at the bottom then SELECTED_ENV will be local. Is it a bug that user defined variables ignore if controllers? Is there any workaround to do what I want to do?
An alternative I guess is just to disable the other environment scripts but its much simpler in a larger complex script to have this controlled in the way I have pictured below. Keep in mind that I really have a bunch of user defined variables so switching environments I will have to enable/disable several places and it's easy to miss one by mistake.





