【问题标题】:update YAML file using YQ in GitlabCIupdate YAML file using YQ in GitlabCI
【发布时间】:2022-12-02 05:27:43
【问题描述】:

So basically, I have this command that runs in Gitlab CI to update a field in YAML configuration before packaging and pushing a Helm chart.

yq -i -y ".pod.image.imageTag="${CI_COMMIT_SHORT_SHA}"" deployment/values.yaml

values.yaml

pod:
  image:
    repository: my.private.repo/my-project
    imageTag: 'latest'
  nodegroupName: "nessie-nodegroup"

But I keep getting this error.

jq: error: syntax error, unexpected IDENT, expecting $end (Unix shell quoting issues?)
.pod.image.imageTag=4c0118bf  

The variable is actually read but it looks like I'm doing something wrong in the yq command. Any ideas where that error is coming from ? Trying with only one quote doesn't read the environment variable obviously. I already tried it.

Update:

Trying with :

yq -i -y '.pod.image.imageTag="${CI_COMMIT_SHORT_SHA}"' deployment/values.yaml

and

yq -i -y .pod.image.imageTag="${CI_COMMIT_SHORT_SHA}" deployment/values.yaml

didn't work either.

【问题讨论】:

    标签: gitlab-ci jq yq


    【解决方案1】:

    With the -y option I assume you are using the kislyuk/yq implementation.

    Use jq's --arg option to introduce values from shell:

    yq -i -y --arg tag "${CI_COMMIT_SHORT_SHA}" '.pod.image.imageTag=$tag' deployment/values.yaml
    

    【讨论】: