I need to make an API callout in pre-request script. This API requires authentication. Required credentials are available as Shell variables set from Jenkins. Configuring Postman environment with these credentials is my last preference because these credential life cycle is managed from Jenkins and I don’t want a dependency on my code. Is it possible to access Shell variables from test scripts? If yes, how?
Hey @ronson
Welcome to the community!!
I recently answered a question in a different forum around being able to use System Environment
variables, within a Collection - I’m not sure how you’re running the Collections from Jenkins but I assume it’s using Newman.
This method might help here, I’m not a Jenkins person so I wouldn’t know for sure but might be worth a go
Basic example but if you have a password stored at the System Environment level, you could use it within the collection like this:
newman run collection.json --env-var password=$PASSWORD
That will resolve the {{password}} variable in the collection to that value.
This was exactly what I was looking for. Worked as expected. Thank you!
That’s awesome to hear!!! Glad I could help!
if the environment file is a json , the syntax is working fine.
But when i try to use a csv file --env-var password=$PASSWORD is not working.
Can you please help with the syntax
I’m not sure I follow what you mean here.
Can you include more context about how you’re using this?
This topic was centered around the Newman command line argument and passing in shell variables, this wouldn’t work if you’re using a data file as the reference wouldn’t resolve that system level value.