Search code examples
gitlab-ci

modify gitlab ci yaml branch name variable to replace / with -


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

Solution

  • 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 / _)