Windows/PowerShell: fails when using environment variables containing dashes
## Summary On Windows, Unreal Engine uses some environment like `UE-LocalDataCachePath` that contains dashes and this make the runner fails the script step (at least when using PowerShell). ## Steps to reproduce * Setup a GitLab Runner instance on Windows With the following config (`C:\GitLab-Runner\config.toml`):  ```toml [[runners]] name = "winbuild3" url = "..." token = "..." limit = 1 executor = "shell" shell = "powershell" builds_dir = "W:\\gitlab-jobs" cache_dir = "W:\\gitlab-cache" environment = [ "UE-LocalDataCachePath=W:\\unreal-cache", ] ``` * Run any job on this runner <!--Please add the definition of the job from `.gitlab-ci.yml` that is failing inside of the code blocks (```) below.--> <details> <summary>.gitlab-ci.yml</summary> ```yml stages: - build - deploy build: stage: build script: - echo Hello World ``` </details> ## Actual behavior Fails with the following errors: ``` Executing "step_script" stage of the job script 00:04 At line:96 char:4 + $UE-LocalDataCachePath="W:\unreal-cache" + ~~~~~~~~~~~~~~~~~~~ Unexpected token '-LocalDataCachePath' in expression or statement. At line:97 char:8 + $env:UE-LocalDataCachePath=$UE-LocalDataCachePath + ~~~~~~~~~~~~~~~~~~~ Unexpected token '-LocalDataCachePath' in expression or statement. At line:97 char:31 + $env:UE-LocalDataCachePath=$UE-LocalDataCachePath + ~~~~~~~~~~~~~~~~~~~ Unexpected token '-LocalDataCachePath' in expression or statement. At line:1 char:3 + & { + ~ Missing closing '}' in statement block or type definition. At line:96 char:1 + $UE-LocalDataCachePath="W:\unreal-cache" ``` ## Expected behavior No syntax error ## Relevant logs and/or screenshots None ## Environment description * We use self hosted runner and a self-hosted GitLab instance. * We use the shell executor (and powershell as shell) <details> <summary>config.toml contents</summary> ```toml concurrent = 1 check_interval = 0 shutdown_timeout = 0 [session_server] session_timeout = 1800 [[runners]] name = "winbuild3" url = "..." token = "..." limit = 1 executor = "shell" shell = "powershell" builds_dir = "W:\\gitlab-jobs" cache_dir = "W:\\gitlab-cache" environment = [ "UE-LocalDataCachePath=W:\\unreal-cache", ] ``` </details> ### Used GitLab Runner version ``` .\gitlab-runner.exe --version Version: 18.6.6 Git revision: df85dadf Git branch: 18-6-stable GO version: go1.24.11 X:cacheprog Built: 2025-12-09T21:36:46Z OS/Arch: windows/amd64 ``` ## Possible fixes I think the issue is located in `variables.go:176`: ```go func (s shellFormatter) EnvName(name string) string { switch s { case shells.SNPwsh, shells.SNPowershell: return "$env:" + name default: return "$" + name } } ``` The problem is caused by the way GitLab Runner writes env var using the `$env:MY_VAR` syntax. To fix the issue, it should use the `${env:MY_VAR}` syntax that works with variable names containing dashes, dot and other uncommon chars. A possible fix could be: ```go func (s shellFormatter) EnvName(name string) string { switch s { case shells.SNPwsh, shells.SNPowershell: return "${env:" + name + "}" default: return "$" + name } } ```
issue