How to Pass Json Parameters for Jenkins Using Curl?

I'm trying to build a job by passing JSON parameter for Jenkins through Linux CLI. But I'm not able to pass the parameters in JSON. I have used -g to turn off globbing. Still the issue persists. Any help would be appreciated.

curl -X POST -u username:password -g JENKINS_URL/job/Bulk_Job/buildWithParameters?serviceBranchJson="{"key1":"value1","key2":"value2"}"}

Error message

Processing provided DSL script
{key1:value1,key2:value2}}
groovy.json.JsonException: expecting '}' or ',' but got current char 'k' with an int value of 107

The current character read is 'k' with an int value of 107
expecting '}' or ',' but got current char 'k' with an int value of 107
line number 1
index number 1
{key1:value1,key2:value2}}

Code snippet

import groovy.json.JsonSlurper

def serviceBranchJson = serviceBranchJson

println(serviceBranchJson)

Map servicesMap = new JsonSlurper().parseText(serviceBranchJson)
1

1 Answer

First: the number of left and right curly brackets does not match (one left, two right). Second: When you type parameters in quotes on command line the shell understands it like "do not touch what's inside" but passes it to the process without quotes. See the result of this example:

echo "{"key1":"value1","key2":"value2"}"

So I'd try to enclose the whole expression in single quotes or escape the single quotes, something like this:

echo '{"key1":"value1","key2":"value2"}'

or this:

echo "{\"key1\":\"value1\",\"key2\":\"value2\"}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest