【问题标题】:Shell variables in yq 4 using env()yq 4 中的 Shell 变量使用 env()
【发布时间】:2022-12-02 19:47:41
【问题描述】:

I want to build a pipeline function that replaces a value in a yaml file. For that I want to make both the pattern and the replacement value variable. I have seen the env-variables-operators article in the yq docs, however I cannot find the relevant section.

I have a yaml file with the following content:

---
spec:
  source:
    helm:
      parameters:
        - name: \"image.tag\"
          value: \"1.0.0\"

I now want to build a pipeline function that will replace the value of the value key in the yaml. I can do so with:

$ yq \'.spec.source.helm.parameters[0].value = \"2.0.0\"\' myyaml.yml
---
spec:
  source:
    helm:
      parameters:
        - name: \"image.tag\"
          value: \"2.0.0\"

Now I want to make this command customizable. What works:

$ VALUE=3.0.0
$ replacement=$VALUE yq \'.spec.source.helm.parameters[0].value = env(replacement)\' myyaml.yml
---
spec:
  source:
    helm:
      parameters:
        - name: \"image.tag\"
          value: \"3.0.0\"

What doesn\'t work

$ VALUE=3.0.0
$ PATTERN=.spec.source.helm.parameters[0].value
$ replacement=$VALUE pattern=$PATTERN yq \'env(pattern) = env(replacement)\'
spec:
  source:
    helm:
      parameters:
        - name: \"image.tag\"
          value: \"1.0.0\"

I have also tried to use strenv and wrapping the replacement pattern in quotes, but it is not working. Can anyone help me with the correct syntax?

    标签: shell yq


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2020-03-05
    • 1970-01-01
    • 2018-01-31
    • 2020-12-24
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    相关资源
    最近更新 更多