我有一个如下所示的 yaml 文件:
apiVersion: v1
entries:
blue-green-toggle:
- description: Used to toggle an application between blue and green
name: blue-green-toggle
version: 1.0.17
apiVersion: v2
- description: Used to toggle an application between blue and green
name: blue-green-toggle
version: 1.0.16
apiVersion: v2
- description: Used to toggle an application between blue and green
name: blue-green-toggle
version: 1.0.15
apiVersion: v2
istio-config:
- description: Used to configure the cluster level settings of istio.
name: istio-config
version: 1.0.4
apiVersion: v2
- description: Used to configure the cluster level settings of istio.
name: istio-config
version: 1.0.1
apiVersion: v2
latest-toggle:
name: latest-toggle
version: 1.0.5
apiVersion: v2
standard-helm-chart:
name: standard-helm-chart
version: 1.1.10
apiVersion: v2
name: standard-helm-chart
version: 2.0.1
apiVersion: v2
name: standard-helm-chart
version: 1.0.34
apiVersion: v2
name: standard-helm-chart
version: 1.0.10
apiVersion: v2
name: standard-helm-chart
version: 1.0.9
apiVersion: v2
generated: 2021-06-22T00:22:33.1554922Z
...
Run Code Online (Sandbox Code Playgroud)
我试图列出version
以 和 开头的数字,1.0.
并在该部分中列出standard-helm-chart
。
到目前为止,我已经使用它来获取以下条目standard-helm-chart
:
yq eval '.entries | .standard-arup-helm-chart' index.yaml
Run Code Online (Sandbox Code Playgroud)
效果很好。然后我尝试仅获取具有version
匹配的行1.0.*
。我阅读了 的select文档yq
,但它没有指示当您查看对象而不仅仅是字符串时如何匹配。
我试过这个:
yq eval '.entries | .standard-arup-helm-chart | select(. == "1.0.*")' index.yaml
Run Code Online (Sandbox Code Playgroud)
但这失败了。我希望它能够,因为它无法将“1.0.*”字符串与整个对象进行比较。
我也尝试过:
yq eval '.entries | .standard-arup-helm-chart | select(.version == "1.0.*")' index.yaml
Run Code Online (Sandbox Code Playgroud)
我想这会让我yq
知道我只想看看这个版本。但它说Error: Cannot index array with 'version'
然后我想我需要尝试数组样式语法:
yq eval '.entries | .standard-arup-helm-chart | select(.[version] == "1.0.*")' index.yaml
Run Code Online (Sandbox Code Playgroud)
但由于解析错误而失败。
我可以发送什么命令yq
来获取所有以 开头的版本号1.0.
?
尝试了一些错误,但这就是我最终得到的结果:
yq eval '.entries.standard-helm-chart.[] | select(.version == "1.0.*") | .version' index.yaml
Run Code Online (Sandbox Code Playgroud)