Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 213
nozzleman Avatar asked Jul 22 '15 11:07

nozzleman


People also ask

How do I use variables in Gitlab?

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.

Where can I find Gitlab variables?

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.

How do I add a variable to a Gitlab group?

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.


1 Answers

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

like image 116
Jim Avatar answered Oct 15 '22 07:10

Jim