Unable to read pre request script while running postman CLI

I have pre request script in my postman test. When i am running manually via postman GUI, there is no issue and it is reading the pre request script but when i tried to run through CLI using API key, it seems that it is not reading the pre request script and all my test which have pre request script is getting failed.
Any config required to read pre request during running from CLI?

Hey @ameneh1986 :wave:t2:

Welcome to the Postman Community :postman:

Could you provide more context about the script and what the script is actually doing, please?

Hey @danny-dainton
Below is details in my pre request:

// Generate a current timestamp in ISO format
var currentDate = new Date();

// Generate a random number of days (1 -30)
var randomDays = Math.floor(Math.random() * 30) + 1;

// Add the random no of days to the current date and update date and save in env:

currentDate.setDate(currentDate.getDate() + randomDays);
var randomIsoTimestamp = currentDate.toISOString();

pm.environment.set("randomIsoTimestamp", randomIsoTimestamp);
1 Like

What’s the Postman CLI command that’s being used and the version of the CLI that you’re using?

Hi @danny-dainton
Not sure it is the thing that you are looking oe not:

Postman CLI command preview

stages:

  • automated-api-tests

automated-api-tests:

stage: automated-api-tests

image: cimg/base: 2021.04 before_script:

Installing Postman CLI

Login using your Postman API keys

  • postman login --with-api-key $POSTMAN_API_KEY
  • postman collection run “28067525-e1f57cd4-e870-489d-9460-4d56a855f60d” - e
    “28067525-b81a2f68-852b-4d14-890e-5c73436cba39”

Dear @danny-dainton
I also tried with latest image and still it is failing

automated-api-tests:
  stage: post-development-tests
  image: cimg/base:2024.09
  before_script:
    - curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh
  script:
    - postman login --with-api-key $POSTMAN_API_KEY
    - postman collection run 28067525-e1f57cd4-e870-489d-9460-4d56a855f60d -e 28067525-b81a2f68-852b-4d14-890e-5c73436cba39
  artifacts:
    paths:
      - automated-api-tests-status.txt
  only:
    - develop
  tags:
    - aks-test01
  allow_failure: true
  when: delayed
  start_in: 5 minutes
1 Like

Taking a look at this now and I’ve raised this with the team - I will update the thread if I have anymore information.

1 Like

Hey @ameneh1986

Were not able to reproduce this on our side using your script.

As you can see it’s resolved the variable from the pre-request scripts that that executed during the run.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.