Your curl
-d
argument command is surrounded with single-quotes.
curl -d '{"color":"green","message":"${BUILD_NUMBER}","notify":false,"message_format":"text"}' -H 'Content-Type: application/json' http:blahbah.com'
In general (at least in bash
) "Single quotes won't interpolate anything, but double quotes will (for example variables, backticks, certain \ escapes, etc...)".
With Jenkins Pipelines, you need to be careful about the quote escaping that is provided. You can see some of the strange behaviors documented here.
One way to handle this case is to substitute the env.BUILD_NUMBER
value in Groovy rather than at shell evaluation. Groovy's triple-quoted strings can also help with string quoting:
sh """curl -d '{"color":"green","message":"${env.BUILD_NUMBER}","notify":false,"message_format":"text"}' -H 'Content-Type: application/json' http:blahbah.com'"""
Here I:
- Surround the entire command with
"""
. Double quotes are used for string interpolation and triple quotes are used to simplify the quoting inside for the curl
command JSON.
${env.BUILD_NUMBER}
is Groovy interpolated into the JSON body