curl -X POST --data-urlencode 'payload={"text": "A new version has been deployed to production."}' https://hooks.slack.com/services/XXXXXXX/XXXXXXXXX/XXXXXXXXXXXXX
我需要在具有Yaml支持的GitLab CI文件中使用它.
Yaml解析器不接受它.通常我会用引号括起来,但我已经在命令中使用了引号和撇号.
这就是命令现在的样子.
如何正确地逃避序列?
deploy: stage: deploy script: - "curl -X POST --data-urlencode 'payload={"text": "A new version has been deployed to production."}' https://hooks.slack.com/services/XXXXXXX/XXXXXXXXX/XXXXXXXXXXXXX"解决方法 最简单的方法是使用块标量:
deploy: stage: deploy script: |- curl -X POST --data-urlencode 'payload={"text": "A new version has been deployed to production."}' https://hooks.slack.com/services/XXXXXXX/XXXXXXXXX/XXXXXXXXXXXXX
|启动一个文字块标量,– 告诉YAML丢弃尾随换行符(否则它将成为标量的一部分).为了便于阅读,您可以使用折叠块标量(换行符将转换为空格):
deploy: stage: deploy script: >- curl -X POST --data-urlencode 'payload={"text": "A new version has been deployed to production."}' https://hooks.slack.com/services/XXXXXXX/XXXXXXXXX/XXXXXXXXXXXXX
最后,也可以使用双引号,只要你在标量内转义双引号(换行符也会折叠成空格):
deploy: stage: deploy script: "curl -X POST --data-urlencode 'payload={\"text\": \"A new version has been deployed to production.\"}' https://hooks.slack.com/services/XXXXXXX/XXXXXXXXX/XXXXXXXXXXXXX"总结
以上是内存溢出为你收集整理的在Yaml中转义包含引号和撇号的cURL命令全部内容,希望文章能够帮你解决在Yaml中转义包含引号和撇号的cURL命令所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)