I want to replace a variable in my .yml file with a variable from the gitlab ci pipeline.
gitlab-ci.yml
deploy_test:
stage: deploy
script:
- sed -i 's/$TAG/$CI_COMMIT_REF_NAME/g' deploy/test.yml
- kubectl apply -f deploy/test.yml
when: manual
only:
- master
- tags
This says within the deploy/test.yml file it should replace $TAG with the value of $CI_COMMIT_REF_NAME?
deploy/test.yml
image: git.<removed>.com:5005/eng/my-group/my-image:$TAG
Use double quotes(") instead of single quotes (') in sed and also take note that forward slashes (/) need to be escaped too.
so given the following (assuming you are using docker hub)
$CI_COMMIT_REF_NAME=docker_user/repo:v1
You will firstly need to escape the '/' character first, like so
$CI_COMMIT_REF_NAME=docker_user\/repo:v1
Then finally use double quotes in the sed command
sed -i "s/$TAG/$CI_COMMIT_REF_NAME/g" deploy/test.yml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With