I can't find out how to access variables in a build-script provided by the gitlab-ci.yml
-file.
I have tried to declare variables in two ways:
config.toml
I try to access them in my gitlab-ci.yml
-files commands like that:
msbuild ci.msbuild [...] /p:Configuration=Release;NuGetOutputDir="$PACKAGE_SOURCE"
where $PACKAGE_SOURCE
is the desired variable (PACKAGE_SOURCE
) but it does not work (it does not seem to be replaced). Executing the same command manually works just as expected (replacing the variable name with its content)
Is there some other syntax required i am not aware of?
I have tried:
$PACKAGE_SOURCE
$(PACKAGE_SOURCE)
${PACKAGE_SOURCE}
PS: Verifying the runner raises no issues, if this matters.
yml file. To create or edit variables in the project, go to the settings from that project: On your project's Settings > CI/CD, then expand the Variables section.
In GitLab, CI/CD variables can be defined by going to Settings » CI/CD » Variables, or by simply defining them in the . gitlab-ci. yml file.
If you have GitLab 9.4+, you can set up group-level environment variables like this: Navigate to your Group. Go to Settings > CI/CD > Variables . Group variables will be inherited by the group's projects and sub-groups.
I presume you are using Windows for your runner? I was having the same issue myself and couldn't even get the following to work:
script:
- echo $MySecret
However, reading the Gitlab documentation it has an entry for the syntax of environment variables in job scripts:
To access environment variables, use the syntax for your Runner’s shell
Which makes sense as most of the examples given are for bash runners. For my windows runner, it uses %variable%
.
I changed my script to the following, which worked for me. (Confirmed by watching the build output.)
script:
- echo %MySecret%
If you're using the powershell for your runner, the syntax would be $env:MySecret
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With