问题
I have the following two commands executed inside a pipeline
def IMAGE = "url/microservices/currency-converter-search:${env.BUILD_NUMBER}"
sh "cat task-blueprint.json | jq .containerDefinitions[0].image=${IMAGE} > currency-converter-search-task-${env.BUILD_NUMBER}.json"
the problem is that I get back an error because the string that I need to save need to be surrounded by "
double quote in order to be save by jq
This is the error I get:
[workspace] Running shell script
+ jq .containerDefinitions[0].image=264721266761.dkr.ecr.us-east-1.amazonaws.com/currency-converter/search:1
error: syntax error, unexpected IDENT, expecting $end
.containerDefinitions[0].image=264721266761.dkr.ecr.us-east-1.amazonaws.com/currency-converter/search:1
^^^
1 compile error
+ cat task-blueprint.json
cat: write error: Broken pipe
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
GitHub has been notified of this commit’s build result
ERROR: script returned exit code 1
Finished: FAILURE
and here you can find my file
https://github.com/mazzy89/currency-converter-search/blob/develop/Jenkinsfile#L26
回答1:
Just escaped the quotes
...image=\"${IMAGE}\"
来源:https://stackoverflow.com/questions/37880208/escape-correctly-double-quotes