Search code examples
jmeterglobal-variables

Passing global variables between Thread Groups


I'm new to jmeter and I'm trying to play around to learn how to pass global variables from one Thread Group to another I built this small script enter image description here

In User Defined Variables, I created 1 variable like this: enter image description here

In JSR223 Sampler 1, I added the following code:

log.info("access_token before 1 = " + vars.get("access_token"))
vars.put("access_token", "aaaaa")
log.info("access_token after  2 = " + vars.get("access_token"))

In JSR223 Sampler 2, I added the following code:

log.info("access_token 2 = " + vars.get("access_token"))

I got the following log entries related to my code:

2024-04-26 21:08:00,241 INFO o.a.j.p.j.s.J.JSR223 Sampler 1: access_token before 1 = 
2024-04-26 21:08:00,241 INFO o.a.j.p.j.s.J.JSR223 Sampler 1: access_token after  2 = aaaaa
2024-04-26 21:08:00,273 INFO o.a.j.p.j.s.J.JSR223 Sampler 2: access_token 2 = 

I was expecting to see the right value of access_token variable inside thread group 2 and see it's value in the log but it was not the case as shown in the logs above.

Can someone please help me out here and show me what I'm missing in my tiny script. Thank you


Solution

  • The trick was to use props instead of vars. It worked.