【发布时间】:2020-02-09 01:02:54
【问题描述】:
我有这样的代码:
import ruamel.yaml
from ruamel.yaml.scalarstring import DoubleQuotedScalarString as dq
yaml = ruamel.yaml.YAML()
yaml.indent(sequence=2)
yaml.preserve_quotes = True
yaml.default_flow_style=None
CF2_cloudbuild = {
'steps':[
{'name': dq("gcr.io/cloud-builders/gcloud"),
'args': ["functions", "deploy", "publish_resized"],
'timeout': dq("1600s")}
]
}
with open("file.yaml", 'w') as fp:
yaml.dump(CF2_cloudbuild, fp)
这是file.yaml的内容:
steps:
- name: "gcr.io/cloud-builders/gcloud"
args: [functions, deploy, publish_resized]
timeout: "1600s"
我需要:
steps:
- name: "gcr.io/cloud-builders/gcloud"
args: ["functions", "deploy", "publish_resized"]
timeout: "1600s"
为了使格式符合有关构建配置文件GCP Build configuration overview docs的 GCP 文档
如何获得?
当我尝试使用 [dq("functions"), dq("deploy"), dq("publish_resized")] 功能时,我得到:
steps:
- name: "gcr.io/cloud-builders/gcloud"
args:
- "functions"
- "deploy"
- "publish_resized"
timeout: "1600s"
我认为和["functions", "deploy", "publish_resized"]不一样。
【问题讨论】:
-
args:和-是一个列表。为什么这对你不起作用? -
我只是从它开始,所以我想我不知道这两个是等价的 - 我的意思是
["functions", "deploy", "publish_resized"]和-相同但相同。谢谢你的澄清:) -
不仅列表等价,双引号也是多余的,因为标量不能被标准 YAML 解析器解释为字符串。
标签: python google-cloud-platform yaml google-cloud-build ruamel.yaml