1

I have a postman collection which I have managed to run from Jenkins using Newman.

I have a groovy pipeline in which I install the dependencies included in my package.json (Newman in this case). From here, I can run a shell script to call the collection:

  stage( 'DEV: Install Dependencies' ) {
      sh 'npm install -g newman'
      sh 'npm install'
  }

  stage( 'Running API Tests') {
  sh 'bash ./scripts_uat/create-new-product.sh'
}

create-new-product.sh calls the parameterized create-new-product.json which uses a number of global vars held in a file global-vars.json, a snippet of which below:

   //create-new-product.json
    .... 
    "body": {
                "mode": "raw",
                "raw": "{\n  \"dept\": \"{{department}}\",\n  \"prodId\": \". 
 {{productId}}\",\n...

I am unclear how I can expose the global vars within Jenkins such that they can be passed as Choice Params from within Jenkins.

A snippet of the global-vars.json:

{
"_": {
"postman_variable_scope": "globals",
"postman_exported_at": "2020-02-27T14:37:33.884Z",
"postman_exported_using": "Newman/4.5.7"
},
"id": "3147c1d3-e108-4689-ad7b-0cc719647103",
"name": "globals",
"values": [
  {
  "type": "any",
  "value": "8293004039",
  "key": "product_id"
  },// more vars

How would I expose {{productID}} such that it can override the value within global-vars.json?

Can anyone give me some pointers? There is probably a better way of doing this.

1 Answer 1

2

https://github.com/postmanlabs/newman#newman-options

This gives the entire command-line options for Newman

so you can use --global-var "<global-variable-name>=<global-variable-value>" to override global variable values.

As we know the precedence of variables is as follows:

(Precedence increase top to button , meaning local> has more precedence than global)

enter image description here

so passing an environmental variable as : --env-var "<environment-variable-name>=<environment-variable-value>"

will also override the value

3
  • thank you, that makes sense
    – Steerpike
    Commented Mar 30, 2020 at 13:17
  • @Steerpike could you up vote also
    – PDHide
    Commented Mar 30, 2020 at 13:21
  • 1
    apologies, now done :)
    – Steerpike
    Commented Mar 30, 2020 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.