How to access variables in gitlab-ci.yml using gitlab-ci-multi-runner on windows

nozzleman picture nozzleman · Jul 22, 2015 · Viewed 10.3k times · Source

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:

  1. Private Variables in the Web-Interface of GitLab CI
  2. Variable overrides/apennding in 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.

Answer

Jim picture Jim · Jul 25, 2015

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