In my GitLab CI script, I am creating a new user which then executes a command. I'm noticing that when the command is executed as this user, the CI environment variables aren't available.
Below is what I do:
before_script:
- useradd -U -d "$CI_PROJECT_DIR" newuser
test-app:
stage: test
image: open-jdk
script:
- echo $MY_CI_VAR #here I can see the env var set in GitLab CI
- su newuser -l -c "grails test-app -unit FooHelper" #in the code it is not available
Question
Is there a way to pass environment variables either when creating a new user or when executing a command as that user.