3

My environment requires the use of the predefined variable CI_PROJECT_NAMESPACE in .gitlab-ci.yml; however, this variable is in all caps, which makes my build job fail. I've tried several ways to convert the value of this variable to all lowercase with no success:

variables:
  CI_PROJECT_NAMESPACE: $CI_PROJECT_NAMESPACE | tr '[:upper:]' '[:lower:]' # doesn't work

build_image:
  stage: build
  image:
    name: #...
    entrypoint: #...
  before_script:
    - export CI_PROJECT_NAMESPACE=$CI_PROJECT_NAMESPACE | tr '[:upper:]' '[:lower:]' # also doesn't work

I have successfully hard-coded this variable for my own use, but I need the script to work for other users as well without requiring them to hard-code it themselves. Thanks in advance for your thoughts!

1
  • You're on the right track with your before_script, but there are some quoting issues. It helps to test out these commands in a local shell first.
    – LLlAMnYP
    Commented Feb 16, 2023 at 2:48

1 Answer 1

2

You had it almost right. You just can't pipe variable itself to tr. You have to use echo in command substitution, which you can pipe to tr.

before_script:
- export CI_PROJECT_NAMESPACE=$(echo "$CI_PROJECT_NAMESPACE" | tr '[:upper:]' '[:lower:]')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.