GitLab CI environment variables

I want to setup a CI/CD pipeline in GitLab.
In my testscript I need a password and a username that I don’t want to have in the repo.
Is it possible to use the GitLab environment variables to pass this to the script?

My idea is that I would access the GitLab environment variables and pass them to the Julia environment variables.

- echo $USERNAME
- julia --project=@. -e 'import Pkg;
            ENV["USERNAME"] = "$USERNAME";
            ENV["PASSWORD"] = "$PASSWORD";
            Pkg.test(; coverage = true);'

The echo works but I’m not able to use the variable in the Julia code.
I get the Julia error:

ERROR: UndefVarError: USERNAME not define

Thanks!

If you export the variables in the shell you don’t need to set them in the Julia process. Your julia call fails because the command is single-quoted, which prevents shell variable interpolation, and "$USERNAME" does interpolation of the Julia variable USERNAME which is not set.

3 Likes

Thank you!
I see; the GitLab CI variables can be directly accessed via ENV["USERNAME"] and ENV["PASSWORD"].