Using '--export-collection' does not output updated collection variables

When using the newman CLI (version 5.2.2), there is a requirement to save updated collection variables after a run. To achieve this, -export-collection <path> is being used but variables in the collection at <path> do not contain updated values after a run.

To set a variable value during the run, pm.collectionVariables.set() is being used in a request test.

let jsonResponse = pm.response.json();
pm.collectionVariables.set("myVariable", jsonResponse.value);

When testing the request in Postman, the updated variable value persists in the collection. The same is true if the runner is used with Keep variable values checked.

However, when using the newman CLI the collection variables are not updated after the run.

newman run collection.json --environment environment.json --export-collection collection.json

According to the documentation, --export-collection|globals|environment <path> is -

The path to the file where Newman will output the final collection / global variables / environment variables file before completing a run.

Testing shows that setting a global/environment variable in the request and using --export-globals|environment <path> works, with the output file containing the updated variable value.

Is this a bug with the newman CLI, or is there something that can be done to fix this behaviour?

Thanks,
David


This question is also on Stack Overflow.

Hey @dgard1981 :wave: Welcome to the Postman Community :tada:

Thanks for reporting this. I was able to reproduce the behaviour where the exported collection variables are not updated.

I am currently checking with our internal team if this is an expected behaviour.
I will let you know once I find out more :smiley:

Hey @dgard1981,

We now have an open GitHub issue filed here:

Please feel free to subscribe to it or add your comments so that you will receive updates :smiley:

Thanks @taehoshino, hopefully this is an easy one to resolve in an upcoming release.

Thanks,
David

1 Like