Quoting YAML (for Travis CI)

谁说胖子不能爱 提交于 2019-12-05 00:45:07

The most elegant solution is to use the literal style | indicator, with the - modifier to strip the final newline. That way there are no extra quotes necessary.

If this scalar happens to be the only thing in a YAML file use:

|-
  json='{"title": "travis_saulshanabrook_site","key": "'$(cat ~/.ssh/id_rsa.pub)'"}'

if it is a mapping value for key abc:

abc: |-
  json='{"title": "travis_saulshanabrook_site","key": "'$(cat ~/.ssh/id_rsa.pub)'"}'

or if it is part of a list:

- |-
  json='{"title": "travis_saulshanabrook_site","key": "'$(cat ~/.ssh/id_rsa.pub)'"}'

I'm not sure there's a solution that makes escapes that string and makes it easy to read.

FYI this is what that string looks like escaped :

script: ! 'your_cmd json=''{"title": "travis_saulshanabrook_site","key": "''$(cat ~/.ssh/id_rsa.pub)''"}'''
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!