Skip to main content
Back to blog
tutorials 23 March 2020 2 min read

JMeter Global Properties

This article explains how to use Apache JMeter's global variables (properties) to share data across thread groups and create reusable test plans for multiple environments.

M

Mark

Performance Testing Expert

This post discusses Apache JMeter’s approach to variable scope and demonstrates how to leverage properties for cross-environment testing.

Core Concept

JMeter distinguishes between local variables confined to thread groups and global variables accessible throughout a test plan. If a variable is inside a thread group it will only be visible within it. To share data across multiple thread groups, developers should use JMeter properties instead.

Practical Application

The strategy presented here builds environment-agnostic test plans. Rather than maintaining separate assets for integration, system test, and pre-production environments, developers define prefixed variables:

  • integration_*
  • syst_*
  • preprod_*

Each prefix precedes configuration parameters including:

  • Protocol
  • URL
  • Port
  • Username
  • Password
  • Proxy settings

Implementation Technique

A JSR223 sampler reads an environment variable and executes conditional logic via a switch statement:

def env = vars.get("environment")

switch(env) {
    case "integration":
        props.put("protocol", vars.get("integration_protocol"))
        props.put("host", vars.get("integration_host"))
        props.put("port", vars.get("integration_port"))
        break
    case "syst":
        props.put("protocol", vars.get("syst_protocol"))
        props.put("host", vars.get("syst_host"))
        props.put("port", vars.get("syst_port"))
        break
    case "preprod":
        props.put("protocol", vars.get("preprod_protocol"))
        props.put("host", vars.get("preprod_host"))
        props.put("port", vars.get("preprod_port"))
        break
}

The code uses props.put() to assign user-defined variable values to global properties based on the selected environment. This approach enables command-line overrides when necessary.

Key Benefit

This methodology reduces testing assets while maintaining repeatability across different deployment stages.

Further Reading

Tags:

#jmeter #performance-testing #properties #configuration

The cheat sheets, as printable PDFs

All 52 are free to read on the site — no signup. Want them as A4 PDFs you can actually print? The pack covers JMeter, k6, Gatling, Docker, Kubernetes and observability, and costs nothing but an email address.

Get the PDF pack

Delivered by email. Unsubscribe any time — see our privacy policy.

Stuck on this in your own test suite?

I take on fixed-price, fixed-turnaround performance work — script migrations, HAR-to-script conversion and written performance audits. No calls required.

Get in Touch