Windows - multi-line step run:

Recently a repo I work with ran the following step:

- name: bundle install
run: |
gem update --system --no-document --conservative
bundle install --jobs 4 --retry 3

The step ran both lines of script in Ubuntu & macOS, but only the first line ran in Windows.

See starter-workflows/ci/ruby.yml

4 Likes

Hi there MSP-Greg,

That’s interesting behavior to report! That’s not expected and while we’re not sure why that is – we’ve forwarded this internally for our Actions engineers to review further.

1 Like

@msp-greg 

Can you try the following on Windows and see if that gets past the issue?  

- name: bundle install
run: |
call gem update --system --no-document --conservative
bundle install --jobs 4 --retry 3
1 Like

Adding shell: powershell fixed Windows for me, however it breaks ubuntu with ##[error]File not found: 'powershell'

https://github.com/DanTup/github-actions-multiline-issue/runs/226399500

You can use shell: pwsh on all platforms.  (That’s the cross-platform PowerShell Core.  Using shell: powershell will give you the older Windows-only PowerShell.)

1 Like

I’ll give that a go. Is there any way to set the default shell to avoid having to do this in each step?

Also - is this original issue a bug that will be fixed? It seems strange, even if using the original command shell.

Edit: pwsh seems to work as a workaround :slight_smile:

I can also confirm that I’ve run into the issue with the following step:

- name: Package
      run: |
        mkdir build/package
        node ./ci/packager.js

It only executed the mkdir part and not the node.js script. The node.js script is to work around another issue in which parameters starting with / or containing . are treated as options to powershell.

Edit: For the time being, I’ve simply moved the mkdir into the packager script.

With the recent change from ‘cmd’ to ‘PowerShell’ as the default Windows script engine/runner, no longer having any problems.

A few multi-line scripts are running fine cross-platform, and multi-line PowerShell scripts are running fine in Windows.

I’d like to close this, but accepting my own post as a solution seems odd…

@msp-greg wrote:

With the recent change from ‘cmd’ to ‘PowerShell’ as the default Windows script engine/runner, no longer having any problems.

I didn’t realise this had changed - seems like a great change - however I think it may have introduced a nasty issue when there are failures in multiline steps on Windows, see:

https://github.community/t5/GitHub-Actions/Multiline-commands-on-Windows-do-not-fail-if-individual-commands/m-p/36848

It seems cmd shell still has this problem so I end up using code like:

- name: Cmd.exe "multiline"
  shell: cmd
  run: >-
    conda info &&
    conda list

Using CALL solved a similiar problem for me. Thanks @chrispat !