Passing environment variable between monitor runs


I am a bit puzzled about how the environment variables are preserved between the monitor runs. So, I have a collection that contains a chain of requests, collects the JSON responses and stores some of the obtained IDs as environment variables at the end of the “Tests” stage of the requests:


Passing the environment variables works just fine within a single collection run performed by a Postman monitor. However, when I try to get environment variable value from the last run, I get the initial value stored into the environment configuration, just as every monitor run would start from scratch. That makes the precautions “if it failed last time, cancel last flow before continue any further” useless.

Am I missing something obvious here? Could that be a side effect of the fact that the environments are shared within the team?

Any ideas or suggestions are very much welcome!

This is one of the differences when running collections in a monitor vs. in the collection runner. Global and environment variables are NOT persisted across collection runs using a monitor the same way they can be persisted across collection runs in the collection runner.

To pass updated environment variables across monitor runs, you can add another call to your collection to update the environment in use. In other words, submit a PUT request using the Postman API to update the environment.

I notice that you said env vars are persisted (if the setting is on) across collection runs. I am trying to do that to persist JWT Tokens in env vars. Not happening.

I set the env var as:
pm.environment.set(‘accessTokenLearner’, jsonData.accessToken);

it works within the collection run but not across it.

Oh btw I just got it. Didn’t notice the check box while starting the run. Thanks. Great product.