Unable to escape colon in Gitab CI/CD yaml

Viewed 27

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?

1 Answers

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'
Related