PowerShell command failures on Windows in travis.yml

We are searching for the right way to formulate some Windows commands in travis.yml.

The failing Travis job can be found here:
https://travis-ci.com/ICB-DCM/AMICI/jobs/261111212

The relevant parts of the job are here:

334 0.55s $ if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then powershell -Command Get-ChildItem ./scripts; fi install.22
374 0.05s $ if [[ "$TRAVIS:OS:NAME" == "windows" ]]; then powershell -Command $VerbosePreference='Continue'; fi install.23
375 0.05s $ if [[ "$TRAVIS:OS:NAME" == "windows" ]]; then powershell -File C:/Users/travis/build/AMICI/scripts/installOpenBLAS.ps1; fi install.24
376 0.05s $ if [[ "$TRAVIS:OS:NAME" == "windows" ]]; then powershell -Command $VerbosePreference='SilentlyContinue'; fi
377 0.05s $ if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then powershell -Command if (Test-Path 'C:\BLAS') {Get-ChildItem 'C:\BLAS' -Recurse}; fi
378 The command "if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then powershell -Command if (Test-Path 'C:\BLAS') {Get-ChildItem 'C:\BLAS' -Recurse}; fi" failed and exited with 1 during .
379
380 Your build has been stopped.
381 From https://github.com/ICB-DCM/AMICI
382 * [new ref] refs/pull/847/head -> develop
383 Switched to branch 'develop'
384 /c/Users/travis/.travis/functions: eval: line 109: syntax error near unexpected token `('
385 /c/Users/travis/.travis/functions: eval: line 109: `if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then powershell -Command if (Test-Path 'C:\BLAS') {Get-ChildItem 'C:\BLAS' -Recurse}; fi '

In line 374, I am enabling PowerShell verbose mode, and the installOpenBLAS.ps1 script starts with

Write-Host 'script installOpenBLAS.ps1 started'

However, I don’t see any output at all, so it looks like the script was not started.

In line 384, you can see that “eval” has a syntax error at the opening parenthesis.

All of this is telling me that I don’t know enough about how to formulate commands in travis.yml. What is wrong with line 375? Do I need to write \( in line 385? Is there any more documentation on this?

I have also added a comment to this post:
https://travis-ci.community/t/powershell-scripts-fail-to-run-with-no-error-message/2288

The commands you provide are executed with Git Bash. So the command line is processed by Bash, according to Bash syntax, before Powershell gets to see it.

In powershell -Command if (Test-Path 'C:\BLAS') {Get-ChildItem 'C:\BLAS' -Recurse}, the entire script should be a single command line parameter. So you need to quote it properly as such according to Bash syntax. Since it contains Bash special symbols, Bash currently interprets it as its own script syntax.

Thanks! This is exactly the kind of information I needed. Now I know that there are 3 levels of logic, first YAML, then Git BASH, the PowerShell. I have already made progress by reading up on BASH, and then I discovered a way to test locally: Using BASH on Ubuntu on Windows Services for Linux on Windows. After installation, PowerShell was automatically available in the Linux PATH variable. That way, I have identified the errors in many of my commands. However, I still need to see what is happening when I call the installOpenBLAS.ps1 script. My next step will be to test the travis “export” command.