Closed labossieresr closed 7 years ago
Hi @labossieresr, system variables are not visible to Postman scripts by default for security reasons. As you mentioned, making this environment on the fly using newman.run is also not a good idea since your secrets might be leaked through logs. Unfortunately, the workaround seems to be your best bet. You could look into this example: https://github.com/postmanlabs/newman#newmanrunevents
@kunagpal might have some more ideas.
@labossieresr The workaround you've provided in the issue description is currently the way to go (for the reasons of security). Additionally, if Newman is being used as a library, you can generate an environment object on the fly using process.env
, and pass it onto newman.run
, like so:
var newman = require('newman'),
env = require('./path/to/env.json');
// here, process.env.COMPUTERNAME is %COMPUTERNAME%
env.values.push({ key: 'COMPUTERNAME', value: process.env.COMPUTERNAME })
newman.run({
collection: '/path/to/collection.json',
environment: env, // environments and collections can be passed as JSON as well.
reporters: ['cli']
}, function (err, summary) {
// do some more stuff here
});
This prevents having to clean up the generated files in the CI based wrapper, and does not pollute your original env.json
file as well.
Thx for the quick and informative responses madebydid and especially kunagpal for the sample code! I tried it out and at first, I got an error as it couldn't find the module 'newman'. I saw in some posts that indicated the NODE_PATH variable needs to be set so I set it to the location of my ....\newman\node_modules folder. Now when I run, it runs without reporting any errors. Unfortunately, it doesn't actually seem to invoke newman. No additional output is displayed and when I purposely make the contents of the collection file bad, it still doesn't generate any errors. Hence, why I think newman.run isn't actually happening.
Do you know what the NODE_PATH environment variable should be set to (maybe more than just what I already did is required) or have any suggestions on how to proceed with troubleshooting? I am thinking it may be environmental. When I perform "newman -v" I get '3.5.2'. But when I do "npm list -g" I see 'newman@3.7.0). Sort of brings me back to the NODE_PATH value.
Also, do you have a good page I can reference to see how to specify other command line options in nodejs (i.e. globals, multiple reporters, disable-unicode). I have been invoking newman via DOS batch but this solution requires me to use nodejs and I see lots of references to how to invoke all the options for it (just not for nodejs). Thx!
@labossieresr I've updated the snippet above, you should be able to use it to see collection run results. The complete list of Newman library options can be found here: https://github.com/postmanlabs/newman#newmanrunoptions-object--callback-function--run-eventemitter
@kunagpal Adding reporters worked like a champ! I was expecting the console output to work like it does for DOS where no arguments/params are required to get the output to display to the console. And thank you also for the reference link!
@labossieresr Glad it worked out for you. Have fun developing in Postman 😄
Issue Report:
How does one access system variables (i.e. %COMPUTERNAME% in Windows) via code within the Pre-request and/or Tests tabs?
My actual goal is integration with CI processes (i.e. Jenkins) and the need to NOT have sensitive information such such as userid's and passwords included within an environment file that gets passed with Newman.
A (very) poor workaround seems to be to have CI process invoke a wrapper that prior to calling Newman looks for the system environment variables and dynamically creates/updates a global or environment file that is then passed in to Newman. There is still the whole security aspect that includes any output you may request Newman to generate (i.e. reports or environment contents) but that can be handled in other ways with more custom post script logic.