HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to change value of pre-defined variable in GitLab to all lowercase

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
lowercaseallgitlabvalueprehowvariablechangedefined

Problem

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!

Solution

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:]')

Code Snippets

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

Context

StackExchange DevOps Q#17439, answer score: 2

Revisions (0)

No revisions yet.