I am following the good practices of naming my branches as dev/myname/featurename How ever this does not play well with the docker image tag name as the forward slashes are not allowed. I am trying to modify the branch name gitlab CI CD variable CI_COMMIT_REF_NAME by replacing / with _ But the below gitlab ci yaml does not do the trick. Any ideas what can be done here ?
build_branch_image:
stage: build
script:
- export
- export BR=$($CI_COMMIT_REF_NAME | tr / _)
- docker build -t mygitlab.com:projectname/containername:$BR -f docker/Dockerfile .
except:
- master
You can use the environment variable $CI_COMMIT_REF_SLUG which replaces the slashes with minus signs.
$CI_COMMIT_REF_NAME=features/my-branch
becomes
$CI_COMMIT_REF_SLUG=features-my-branch
You're using the $CI_COMMIT_REF_NAME directly as a command, which isn't what you meant. You're missing an echo there:
export BR=$(echo $CI_COMMIT_REF_NAME | tr / _)
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