Access Shell variables in Postman test scripts

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!! :star:

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 :grin:

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.

1 Like

This was exactly what I was looking for. Worked as expected. Thank you!

1 Like

That’s awesome to hear!!! Glad I could help!