2

When I attempt to escape my yaml which contains a colon like so:

  script:
    - '${Env:TEMP}/${Env:VAR_VS_VERSION}.exe --layout c:/layout/${Env:VAR_VS_VERSION} --lang en-US --useLatestInstaller --cache --fix --wait --norestart'

I get the following error:

ParserError: 
Line |
 308 |  ${Env:TEMP}/${Env:VAR_VS_VERSION}.exe --layout c:/layout/${Env:VAR_VS .
     |                                          ~~~~~~
     | Unexpected token 'layout' in expression or statement.
ParserError: 
Line |
   1 |  }
     |  ~
     | Unexpected token '}' in expression or statement.

The CI linter is saying everything is valid and the other questions/answers on Stack Overflow don't seem to help.

  • I've tried single and double quotes around my entire command, doesn't work
  • I've tried folding style from here, doesn't work

Any suggestions?

sytech
  • 29,298
  • 3
  • 45
  • 86
Johnny 5
  • 499
  • 5
  • 10
  • use ```\``` to escape – Pavol Krajkovič Aug 17 '22 at 17:17
  • That doesn't work and I still get the error – Johnny 5 Aug 17 '22 at 17:57
  • GitLab and Yaml are incidental to your problem; in PowerShell, an executable path that is _quoted_ or contains _variable references_ (such as in your case) must - for syntactic reasons - be invoked with `&`, the [call operator](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Operators#call-operator-); see the linked duplicate for details. In short (all on one line): `- '& ${Env:TEMP}/${Env:VAR_VS_VERSION}.exe --layout c:/layout/${Env:VAR_VS_VERSION} --lang en-US --useLatestInstaller --cache --fix --wait --norestart'` – mklement0 Aug 17 '22 at 20:57

1 Answers1

2

Your script string from your YAML is being interpreted as intended, the problem is the powershell syntax is wrong.

The part ${Env:TEMP}/${Env:VAR_VS_VERSION}.exe is not valid for calling an executable. In powershell, this is interpreted as division, not string concatenation. However, before powershell attempts to do the division, it validates the entire command string -- because a flag like --token doesn't make sense after a division call, it throws a ParserError. If you remove all the text after .exe you will probably see a RuntimeException that makes this more clear.

Similarly, another example that demonstrates the same problem you have:

1/1 --foo

Will produce:

At line:1 char:7
+ 1/1 --foo
+       ~~~
Unexpected token 'foo' in expression or statement.

To fix your issue, you need to fix your powershell syntax to be valid. What you probably want to do is use the call operator (&) to call your executable:

script:
  - '& ${Env:TEMP}\${Env:VAR_VS_VERSION}.exe --layout c:/layout/${Env:VAR_VS_VERSION} --lang en-US --useLatestInstaller --cache --fix --wait --norestart'
sytech
  • 29,298
  • 3
  • 45
  • 86