Escape correctly double quotes

南笙酒味 提交于 2021-01-28 18:36:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!