如果值是映射或字符串,则使用YQ测试
我有包含两种表格的image
键的YAML:
image: my/dockerimage:1.2.3
并且
image:
description: this i a string
type: another string
我需要处理此YAML并仅过滤键image
是字符串(而不是映射)。
如何使用yq
来执行此操作?
I have YAML that contains the image
key with both forms:
image: my/dockerimage:1.2.3
and
image:
description: this i a string
type: another string
I need to process this YAML and filter only the keys where image
is a string (not a map).
How can I do this with yq
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设 mikefarah/yq 已在此处使用(使用
eval> evar> eval> evar> evary
syntax) ,您可以通过将.image
明确匹配为字符串类型来解决问题,该字符类型表示为!! str
在yq中。 您需要以下需要获得.image
的值因此, /#notice-for-v4.x-versions-prior-to-4.18.1“ rel =“ nofollow noreferrer”>上方4.18.1 ,eval Action
e
是默认值一个并且可以完全跳过。Assuming that mikefarah/yq has been used here (with the
eval
syntax), you can solve the problem by explicitly matching the.image
to be of string type, which is represented as!!str
in yq. So you need below to get the value of.image
Note that, if you are using
yq
version above 4.18.1, the eval actione
is the default one and can be skipped altogether.