Add a $CI_BUILD_REF_SLUG CI variable which is the ref name with only [a-z0-9-] characters
Description
We often use the value of $CI_BUILD_REF_NAME in our .gitlab-ci.yml files, mostly for Docker image tags and review app environment URLs. All would be well and good with this, but most people at our company name branches like <username>/foo, or feature/bar. This means that:
- The ref name can't be used as a docker image tag, since
/is an illegal character there. We ended up adding this to most of our projects'.gitlab-ci.ymlfiles to work around this:before_script: - export NOSLASH_REF_NAME=${CI_BUILD_REF_NAME/\//-} - The ref name can't be used as a review app subdomain directly. We couldn't find any way to make this work, so we're just managing branch deployment URLs outside GitLab.
Proposal
Add a $CI_BUILD_REF_SLUG to the build context which is just the $CI_BUILD_REF_NAME with all letters lowercased, and all non-alphanumeric characters replaced with a dash. So a feature/foo branch would get a slug like feature-foo, and a tag named macOS/v1.0.0 would be slugified as macos-v1-0-0.