Gitlab CI $CI_ENVIRONMENT_URL variable not working

I’m pulling my staging environment variable $CI_ENVIRONMENT_URL in my gitlab-ci.yaml in order to add it as a hostname into a LetsEncrypt-integrated ingress, hoping to avoid manually inserting the hard-coded URL into every project.

However, although I can use the variable in a command such as this:

sed -ri "s|<url>|$CI_ENVIRONMENT_URL|" values.yaml

I found I need to trim the “http://” off the front.

So I inserted a line above it to clean up the URL first:

CLEAN_URL=$(echo CI_ENVIRONMENT_URL| sed -e 's#/##’ -e ‘s#^.*/##’)
sed -ri "s|<url>|$CLEAN_URL|" values.yaml

The result is a blank URL, even though running the above commands in a bash shell results in the intended clean URL.

How can I make this work?