Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass JSON as one of the parameter through a Jenkins Job

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%
like image 544
Sam Avatar asked Apr 03 '18 16:04

Sam


People also ask

How pass parameters to jobs in Jenkins?

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.

Can you pass JSON in a GET request?

To answer your question, yes you may pass JSON in the URI as part of a GET request (provided you URL-encode).

How do you call a parameter in Jenkins?

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.

How do I pass parameters in Groovy script Jenkins?

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.


2 Answers

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.

like image 116
pro_cheats Avatar answered Dec 14 '22 21:12

pro_cheats


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%
like image 36
Sam Avatar answered Dec 14 '22 20:12

Sam