hi,
I create an infrastructure with reusable scripts, so all my scripts are stored in a collection called Library.
I created environment variables
I am using a collection of variables for a test run
And
globals are used to store the functions.
So from my main collection called 'Sanity," I am calling by using
this code
eval(pm.globals.get(“Library_itineraries_get_itineraries_objects_fromSearchAPI”))();
to reuse my scripts.
Problem - now I am trying to create a ci/cd process and I can’t run this all together!
This is the command that I copied from Postman CLI *postman collection run 32090846-92860d15-2359-4903-a5d3-8e8207252b19 -e 32090846-bebc35a4-f9ea-4665-83fd-bb4d2b516748*
If I am running it directly from Postman everything is working great but from CLI all tests are falling
What you want to do can be best achieved by using a single collection with an environment variable. Is there any reason why you’re not storing the reusable script in an environment variable?
Currently, there is no way to run multiple collections in a workspace simultaneously and global variables are not available in CLI runs. Additionally, when using environment variables, ensure that the variables are stored as “initial values” which are synced with Postman servers. Variables stored as “current values” do not get synced with Postman servers are are not shared across a team workspace and hence will not be available in a CLI run.
Both Newman and the Postman CLI run Collections. They don’t have access to the underlying workspace.
The details for a collection run do not persist after the collection run, so if you run one collection, then another, no variables from the first collection run will be available to the second one.
Globals from a work space will not be available.
What you could do is put each script into an environment variable, and eval that instead of the global variable. But you already appear to be using an environment, so I suspect that option won’t work for you.
You could potentially put the scripts into a data file, and then use the data file in your command line, and eval from there. Each script would need to be wrapped in a string and escaped properly. Run the code through an online minifier first.