GitLab CI variables not working in Windows

I use variables to set the build directory for CI. This works well in linux however the variables do not get expanded on my windows runners. Below is a simple example.

In this example on linux $BUILD_DIR gets expanded correctly.
On windows a directory is created with the variable name ($BUILD_DIR) not the variable value.

Is this a bug I should report or am I doing something wrong?

variables: BUILD_DIR: $CI_PROJECT_DIR/$CI_BUILD_REF_NAME/build

testjob:
script:
- mkdir $BUILDDIR

I gues on windows you have to use something like mkdir %BUILDDIR%
the synthax for using environment variables in commands differs from platform to platform

Thanks for your response.

mkdir %BUILDDIR% does expand the variable correctly. However the command does not work because CI_PROJECT_DIR and BUILD_DIR contain / path separators instead of \

Any ideas on the best way to handle this without having to redefine all my variables based on platform?
Should I ping the gitlab guys about this via the issue tracker?

After looking into this a bit more I don’t know the correct syntax for concatenating a path in windows. If I include quotes in the variable definition the variables are not expanded. For example…

.platform_template: &WindowsPlatform
  variables:
    BUILD_DIR: "%CI_PROJECT_DIR%/%CI_BUILD_REF_NAME%/build"
    PLATFORM: 'windows'
  tags:
    - windows

Makes echo BUILD_DIR expand to %CI_PROJECT_DIR%/%CI_BUILD_REF_NAME%/build

If I remove the quotes…

.platform_template: &WindowsPlatform
  variables:
    BUILD_DIR: %CI_PROJECT_DIR%/%CI_BUILD_REF_NAME%/build
    PLATFORM: 'windows'
  tags:
    - windows

the yml is invalid because of the unknown character %

I switched to using a bash shell and everything is working better.

How do you make it to use bash instead of regular shell? I’ve installed the runner using “shell” options but it seems to not work well.

1 Like