6

I want to pass a JSON string to a node using a Jenkins Job.

JSON={"Automation":{"Env":"XXX","No of TCs to Run":"08","Suite":{"SAMPLE1":[{"testcases":"TC01,TC02,TC03,TC04"},{"TC_Username":"test@xxxxx.xom","TC_Password":"P!assword"},{"TS_Username":"test@xxxxx.xom","TS_Password":"AgeAS2"},{"TM_Username":"test@xxxxx.xom","TM_Password":"P!assword","TM_Company":"TEST","TM_FirstName":"Test","TM_LastName":"FARIZ"}]}} }

code in the Build Section of Jenkins jobs:

cd C:\Test
BatchRunner.bat %JSON%
Sam
  • 543
  • 3
  • 10
  • 27

2 Answers2

3

For any batch file passing of the arguments works like this -

greet.bat file -

@echo Hello %1

If you run this as

greet John

It will output

Hello John

For JSON objects as parameters don't forget to use a delimiter backward slash - \ to escape double quotes - "

For example -

"{\"name\":\"abc\",\"place\":\"xyz\"}"

will be passed as -

{"name":"abc","place":"xyz"}`

Hope this helps.

Refer this and this web page for more info.

pro_cheats
  • 1,534
  • 1
  • 15
  • 25
1

I did this by using "This project is parameterized" Option present in Jenkins- General Section.

Include a Multi-line string Parameter where you can pass the JSON as parameter. Include the code in the BUILD section as below:

Note: Make sure the String is valid as you need to enclose them in a double quote.

cd C:\Test
BatchRunner.bat %JSON%
Sam
  • 543
  • 3
  • 10
  • 27