German Varanytsya
German Varanytsya

Reputation: 397

How to use variable in sh curl groovy using quotest?

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

Upvotes: 0

Views: 878

Answers (1)

Dashrath Mundkar
Dashrath Mundkar

Reputation: 9222

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}\\\"}\""

Upvotes: 1

Related Questions