Why Are My Pre-request Script Variables Not Available in Monitor Runs?

Hello

I am running into an issue where variables set in my Pre-request Script work fine during manual runs in the Postman app but fail to initialize properly when I trigger the same collection through Monitors. :slightly_smiling_face:Specifically; I am generating a dynamic timestamp & setting it as an environment variable but in monitor logs, it shows as undefined when referenced later in the request / in test scripts. :upside_down_face:

I have confirmed that the environment is correctly selected in the monitor settings & the script has no syntax errors. :thinking:Everything runs as expected locally but fails silently / returns unexpected values in the monitor context. I have tried adding logging & even reordering the scripts but with no luck so far. :thinking:

Is there something different in how Monitors handle the execution context for pre-request scripts or variable scopes? :thinking: I checked Run API tests using Postman Monitors | Postman Docs guide related to this and found it quite informative. Since we are building a CI/CD pipeline around API testing; understanding what is devops helps highlight the importance of consistency between local & automated test runs something this monitor issue disrupts. :innocent:

Would love to know if others have encountered similar behavior & whether there’s a reliable workaround, like initializing values differently / using global variables instead.

Thank you !! :slightly_smiling_face:

I think the following still applies.

My Monitor is not using variables – Postman

As the monitor is run from the Postman cloud, it has no knowledge of the current value, only the initial value that is held within the Environment.

The article advises to use the Postman API to update the current value within the Environment.

That’s probably a lot of extra code. What is probably going to be easier is to create the dynamic timestamp in an initial step within your CI pipeline and then pass this variable into the command line for the Postman CLI\Newman.