0

如何使用 Mike Farah 的 YQ v4 更新具有特殊字符的字段。

例如在下面操作:

      containers:
        - name: flyway
          image: xx.dkr.ecr.eu-west-1.amazonaws.com/testimage:60

尝试错误:

$ yq e ".spec.template.spec.containers[0].image=xx.dkr.ecr.eu-west-1.amazonaws.com/testimage:61" flyway.yaml
Error: Bad expression, please check expression syntax

$ yq e ".spec.template.spec.containers[0].image=xx\.dkr\.ecr\.eu-west-1\.amazonaws\.com\/testimage:61" flyway.yaml
Error: Parsing expression: Lexer error: could not match text starting at 1:53 failing at 1:54.
        unmatched text: "\\"

#########

$ echo $image
xx.dkr.ecr.eu-west-1.amazonaws.com/testimage:61
$ yq e ".spec.template.spec.containers[0].image=$image" flyway.yaml
Error: Bad expression, please check expression syntax

没有找到任何解释特殊字符的任何转义字符的文件。

4

1 回答 1

0

找到这个文档: https ://mikefarah.gitbook.io/yq/operators/env-variable-operators

这对我有用:

$ echo $image
xx.dkr.ecr.eu-west-1.amazonaws.com/testimage:61
$ myenv=$image yq e '.spec.template.spec.containers[0].image=env(myenv)' flyway.yaml
<<removed contents for brevity >>
    spec:
      containers:
        - name: flyway
          image: xx.dkr.ecr.eu-west-1.amazonaws.com/testimage:61
于 2021-04-28T16:00:08.637 回答