Reputation: 3088
I had a curl call in one of the pipeline steps which was working just fine:
stage("deploy") {
when {
environment ignoreCase: true, name: "DEPLOY_TO", value: "staging"
}
steps {
// copy files from dev to server
sh """rsync...
#....
/bin/cp .....
rm -Rf /tmp/${env.SITEID}docs/
# clear the caches
curl -sS -X POST \"http://www.xxxxxxxx.net/myscript.php?api_key=sdfsdfsdfe&site_id=088\""""
The problem started when I added an if conditional to that curl call in case that curl call failed:
stage("deploy") {
when {
environment ignoreCase: true, name: "DEPLOY_TO", value: "staging"
}
steps {
// copy files from dev to server
sh """rsync...
#....
/bin/cp .....
rm -Rf /tmp/${env.SITEID}docs/
# clear the caches
if [[ $( curl -sS -X POST \"http://www.xxxxxxxx.net/myscript.php?api_key=sdfsdfsdfe&site_id=088\" | jq -r .debug_info.id_info) != \" cache cleared successfuly\" ]]; then exit 255; fi"""
The error is now pointing to the line of code rm -Rf /tmp/${env.SITEID}docs/
but the confusion is that I didn't even changed that line of code!
The error message I get is the following:
ERROR: WorkflowScript: 119: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 119, column 41.
rm -Rf /tmp/${env.SITEID}docs/
Any help is appreciated.
Upvotes: 1
Views: 1829
Reputation: 28784
The problem is still in the line you modified:
if [[ $( curl -sS -X POST \"http://www.xxxxxxxx.net/myscript.php?api_key=sdfsdfsdfe&site_id=088\" | jq -r .debug_info.id_info) != \" cache cleared successfuly\" ]]; then exit 255; fi
Although the output line and column are incorrect, the body of the message is accurate. Note the message:
illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}"
This is because of the part with $( curl
where that dollar sign is being interpreted as denoting a Groovy and/or Jenkins variable interpolated within a string. The two suggestions given in the error are based upon whether you meant that or not. If you meant that, then you need to bracket it like:
${( curl...}
but, since you did not mean that and instead wanted a shell variable interpolation inside the string, you need the former suggestion and escape the $
.
Your resulting line appears like:
if [[ \$( curl -sS -X POST \"http://www.xxxxxxxx.net/myscript.php?api_key=sdfsdfsdfe&site_id=088\" | jq -r .debug_info.id_info) != \" cache cleared successfuly\" ]]; then exit 255; fi
Upvotes: 1