0

I am running a github actions workflow, and I would like to understand why is the sed command unable to inject the GITHUB_RUN_ID in the second command below?

- name: Set ${GITHUB_RUN_ID}
  run: echo "${GITHUB_RUN_ID}" > .github/workflows/run_id

- name: Wait for ${GITHUB_RUN_ID}
  run: wait

- name: Update k8s manifest with new image
  run: |
       cd base/base
       sed -i 's/image *= (.)/image: gitauwairimu/javamvn:${GITHUB_RUN_ID}/g' deployment.yaml
       cat deployment.yaml

The step: name: Set ${GITHUB_RUN_ID} echos the variable but the second doesn't catch on? Why and what can be done about it?

GuiFalourd
  • 15,523
  • 8
  • 44
  • 71
Gitau Wairimu
  • 11
  • 1
  • 4
  • Shell variables don't expand in single quotes. Use double quotes instead. – Azeem Jul 13 '23 at 14:02
  • You can simply use [`yq`](https://github.com/mikefarah/yq) instead of `sed` to work with YAML files. – Azeem Jul 13 '23 at 14:05
  • @Azeem I tried the double quotes and then the yq command: yq -i '.image = "gitauwairimu/javamvn:${GITHUB_RUN_ID}"' deployment.yaml I get same results as before. – Gitau Wairimu Jul 13 '23 at 14:29
  • Double quotes were for the `sed` command. `yq` has different syntax. For `yq`, you may find multiple SO threads how to do that or dive into its docs. – Azeem Jul 13 '23 at 14:45
  • Also, looks like you haven't tested that `sed` locally. You're using `/` as part of your substitution but the image name itself has one i.e. `gitauwairimu/javamvn`. So, you need to switch it to something else e.g. `|`. Example: `sed -i "s|image: .*|image: gitauwairimu/javamvn:${GITHUB_RUN_ID}|g" deployment.yaml` – Azeem Jul 13 '23 at 14:51
  • 1
    This did it: sed -i "s|image: .*|image: gitauwairimu/javamvn:${GITHUB_RUN_ID}|g" deployment.yaml Thanks @Azeem #CI/CD Collective – Gitau Wairimu Jul 13 '23 at 15:51

0 Answers0