正确转义双引号 [英] Escape correctly double quotes

查看:76
本文介绍了正确转义双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在管道中执行了以下两个命令

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"

问题是我返回了一个错误,因为要保存的字符串需要用"双引号括起来才能用 jq

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

这是我得到的错误:

[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

推荐答案

只是忽略了引号

...image=\"${IMAGE}\"

这篇关于正确转义双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆