Newman command line integration with Jenkins

Hi,

Is there any way , can I pass test data from jenkins to API request body?
something like this:

newman run https://www.getpostman.com/collections/XXXXXXXX -d TestData.json='{"parameter":[{"Authenticate": [{"msisdn": "%msisdn%","pin": "%pin%"}]}' --reporters cli

here I want msisdn and pin to be passed from Jenkins to postman testdata file,so that internally it will be passed to Postman request body.

Can we achieve this?

Using the -d flag in the request would need to point to a datafile (JSON/CSV) that has been stored somewhere locally or a URL that returns the data in the correct format.

You could use either --global-var or --env-var to pass data from your Jenkins script into the Collection.

This for example, if the {{foo}} variable was used, it would resolve it to the bar value.

--global-var "foo=bar"

I don’t really know Jenkins very well so I’m not going to be able to give much advice here but you can do something basic to test it out:

--global-var "testing={"parameter":[{"Authenticate": [{"msisdn": "%msisdn%","pin": "%pin%"}]}"

I don’t really know your context behind those variables you’re using so you would need to experiment with that.

Hi, I am passing below command
newman run https://www.getpostman.com/collections/XXXXXXXXXXXXX -d /TestData/QA_Regression_TestData.json --global-var “msisdn=2332234444”

but msisdn value is not overriden by environment variable

msisdn is stored in TestData sheet file.

Is the same variable also being used in the datafile you’re using as well as being set as a global variable on the CLI?

The Newman command alone is pretty meaningless here as that datafile could literally contain anything and the collection could be doing all sorts of things with the data.

Can you expand on all the details of what’s going on and explain what each variable is and where its being used.

Also, you’re using the public URL to reference the collection file, just ensure that if you have made a change in the collection, you need to update the link for those changes to be known to Newman.

Hi Danny,

I am getting data (?e.g msisdn ) from json file.here is acommand which Iam using to get data:
let idArray = pm.iterationData.get(“PhoneNumbers_Available”)
and than
var id = idArray[counter];
pm.environment.set(“msisdn”,id.msisdn);

now I am trying to pass the data from command line instead of data file. and passing --global-var or --env-var, but its not picking from cli

I’m not going to lie, I have no idea what you’re trying to do here from what you’re saying. :grimacing:

The random pieces of code don’t really make any sense in isolation.

Can you DM me the collection and the datafile so I can see what you have got in front of you. Without those it’s going to be tough to help here.

Thanks for your idea.

I just made one change in my scripts. instead of passing pm. environment.set, I passed pm.globals.set in pre request; and in cli, i passed --env-var. This one worked for me.

I got another two issues. Could you please check.

Issue1) I want to pass values from environment variable, if I dont pass from environment variable(–env-var) , this should be picked from the already set value from postman.
Actual:
everytime its picking from --env-var. If I dont pass any value in --env-var, its passing as null or empty.

Issue2) I have key values in “” ,but its skipping double quotes.inLast screensho, deviceprice and monthlybillprice is without double quotes in report , but I passed request as:
{“devicePrice”: 100,“monthlyBillPrice”: 800}

Here is my request and CLI:



newman run https://www.getpostman.com/collections/XXXXXXXXXXX --env-var “msisdn=123456789” --env-var “request={“devicePrice”: 100,“monthlyBillPrice”: 800}” --reporters htmlextra,cli --reporter-htmlextra-export Results/report.html --reporter-htmlextra-template Report/MyReport.hbs

Here in report devicePrice and monthlyBillPrice are without double quotes but I passed double quotes in command line.

Hi Danny,

Is there any update on issue2 . this is critical to me and holding some of my testing.
I have handled issue 1 in shell script, so we can ignore issue 1 now.

Thanks,
Shailendra

Is there an expectation that I’m supposed to be doing something here?

It’s not something I’ve even looked at since responding nearly 2 weeks ago.

I have issue while passing environment variable.Please see issue 2 above.

Have you tried wrapping it in single quotes so it doesn’t think you’re opening and closing the double quotes:

--env-var 'request={"device Price": 100, "monthly Bill Price": 800}' 

image

This isn’t really a Postman problem, it’s the way certain characters (single or double quotes ) are handled by your OS when adding them in a CLI.

I tried this --env-var ‘request=$request’ and my Newman script is in shell script.
OS: Windows10
request={“isCreditCardSaved”:8} sh invoke_digital_api_tests.sh

but I got below in request:

Sorry…–env-var “request=$request’”
request=’{“isCreditCardSaved”:8}’ sh invoke_digital_api_tests.sh

above trick worked for me . Thanks.
We can close this now