Sunday, November 14, 2021

[SOLVED] Quote in curl command in Jenkinsfile

Issue

I try to launch a curl with json data in a jenkinsfile.

But I have strange issue with quote.

CUB_CONFIG = "1614874915062/v0001a0x_test.conf"
url = "https://..."
sh "curl $url -d {'iro': '${CUB_CONFIG}', 'src': '/app/data/'} -H 'Content-Type: application/json'"

It is interpreted like (and so do not work...) :

curl https://... -d '{iro:' 1614874915062/v0001a0x_test.conf, src: '/app/data/}' -H 'Content-Type: application/json'

How I should write these damn quote ??


Solution

{ and } have special meaning in shell scripts, so when a literal { or } character is desired they must be quoted or escaped.

Here is your correct sh call (I use """ so I don't need to use \" escapes):

sh """curl '$url' -d '{"iro": "${CUB_CONFIG}", "src": "/app/data/"}' -H 'Content-Type: application/json'"""


Answered By - Shane Bishop