Home > other >  How to use variable in sh curl groovy using quotest?
How to use variable in sh curl groovy using quotest?

Time:04-08

i have a script

Date date = new Date()
String datePart = date.format("yyyy-MM-dd HH:mm:ss")

sh "curl 'www.link.com' --json '{"datas": "${datePart}"}'"

result is negative...

Ideally result should be curl 'www.link.com' --json '{"datas": "2021-04-07 13:00:00"}'

How could i fix it? i need all quotes to be like in my example and important is that variable should work

CodePudding user response:

I just tried this it should work so use it like this

sh "curl 'www.link.com' --json \'{\"datas\": \"${datePart}\"}'"

OR another alternatives

"curl 'www.link.com' --json \"{\\\"datas\\\": \\\"${datePart}\\\"}\""

  • Related