Flow control to execute one folder instead of another folder

Here’s my use case: I have collections where, depending on the configuration of the environment, I will need to execute different sequences of requests. I will be combining these collections using the NPM package postman-combine-collections and then executing them in Jenkins using the NPM package newman.

Rather than trying to flow control all of my setup/execution/tests in the pre-request and test scripts to change for each configuration (which can, and will, get terribly messy/edge-case-y quickly), I’d like to instead go simpler and create top-level folders in the collection for each configuration.

Like so:

  • Collection 1
    — Configuration 1
    ----- Setup
    ----- Execution
    ----- Teardown
    — Configuration 2
    ----- Setup
    ----- Execution
    ----- Teardown
  • Collection 2
    — Configuration 1
    ----- Setup
    ----- Execution
    ----- Teardown
    — Configuration 2
    ----- Setup
    ----- Execution
    ----- Teardown

What I need to do, then, to execute my combined collection using ‘Configuration 1’ folders instead of ‘Configuration 2’ folders? newman run accepts a --folder <name> option but, as it describes itself:

Run requests within a particular folder/folders in a collection. Multiple folders can be specified by using --folder multiple times, like so: --folder f1 --folder f2 .

It sounds like this will not work for my scenario, as I would have to specify every single folder name (there will be dozens of collections with 2-3 configurations each, which is why I am using postman-combine-collections instead of writing dozens of batch commands in my Jenkins job).

*Further clarification about how I’m executing things in Jenkins:

  1. Configure my software environment (change settings for my deployed services)
  2. Run my Postman collection folders for that particular configuration, which will change things like API flows (which requests ARE made/NOT made) as well as request requirements (which fields are required/not required or allowed/disallowed, which values are valid/invalid for each field)
  3. Repeat steps 1 & 2 for my other configurations

*If you would like to play with behaviors for this, I have made an example combined collection here: https://www.getpostman.com/collections/343ce37d6f59bcbe0d3e (instructions are in the collection’s description for getting started). Remember, the goal is to run both “config 1 (dogs)” or “config 2 (cats)” folders in all collections (imagine there are 36 collections combined here instead of two!)

The only other way to accomplish this that I can think of is somehow flow-controlling within each collection to say which folders run, and which don’t, under a certain environment variable condition? Because I could set an environment variable value when I execute newman run

(i don’t think this is possible to do)

Guess I’m out of luck on this :confused:

Hey @morleym_cubic!

Sorry for the lack of a response here.

I actually built a Collection that does what you’re talking about some time ago (modifying request flow via an environment variable):

Let me know if you have any questions.

It’s based on defining the name of the first request you want sent, and the last:

  1. Collection Run starts
  2. Collection jumps to first specified request
  3. Collection continues running as per normal
  4. Collection reaches last specified request, ends Collection run

So in other words, as long as you can base your run on the name of the first and last request you want sent, this should work.

Let me know if you have any questions!

2 Likes