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)

There’s a lot of questionable things going on here. Is your “Code Snippet” some sort of pipeline script? I’m really not sure what its doing, nor why its assigning a variable to itself, then parsing it.

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

That is absolutely not a valid curl command. you have way too many things double quoted, which ends up not quoting very much. You need to escape anything that goes into a url that isn’t letters or numbers. so you’d want to do serviceBranchJson= then the url encoded the json.

Also I don’t think since your posting, you want to use post variables not get variables (in the url), so you’d want to use -d