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":"[email protected]","TC_Password":"P!assword"},{"TS_Username":"[email protected]","TS_Password":"AgeAS2"},{"TM_Username":"[email protected]","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%
Now you have to configure your Jenkins job. First under General section check “This project is parameterized” option and then select String Parameter option by clicking the “Add Parameter” button. Enter Your parameter name (In my case BROWSER) and default value (In my case Firefox) and click on “Apply” button.
To answer your question, yes you may pass JSON in the URI as part of a GET request (provided you URL-encode).
You just have to use params. [NAME] in places where you need to substitute the parameter. Here is an example of a stage that will be executed based on the condition that we get from the choice parameter. The parameter name is ENVIRONMENT , and we access it in the stage as params.
In the Name field add any name for your parameters and select the Groovy script in the Script radio buttons. Add a suitable description for your parameter. Next is Choice Type dropdown which has 4 choices available. Single Select : It will render a dropdown list from which a user can select only one value.
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.
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%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With