Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 3

Using matrix to specify shell: is it possible?

Solved! Go to Solution.

I'm trying to run a job with two different shells (powershell and pwsh).

 

Attempt #1

If I specify this workflow configuration

name: Test 1
on:
  pull_request:
  push:
    branches:
      - master
jobs:
  test:
    runs-on: windows-latest
    strategy:
      matrix:
        shell: [powershell, pwsh]
    steps:
      - name: Print shell version
        run: $PSVersionTable

 

The output for both the executions is the same (like if matrix.shell is not taken in account):

 

    Run $PSVersionTable
    $PSVersionTable
    shell: C:\Program Files\PowerShell\6\pwsh.EXE -command ". '{0}'"

Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Microsoft Windows 10.0.17763 
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion      

 

 

Attempt #2

If I specify this workflow configuration

 

name: Test 2
on:
  pull_request:
  push:
    branches:
      - master
jobs:
  test:
    runs-on: windows-latest
    strategy:
      matrix:
        shell_name: [powershell, pwsh]
    steps:
      - name: Print shell version
        shell: ${{ matrix.shell_name }}
        run: $PSVersionTable

 

 

The job isn't executed, because of this error:

 

### ERRORED 07:43:52Z

- Your workflow file was invalid: The pipeline is not valid. .github/workflows/test2.yml (Line: 15, Col: 16): Unrecognized named-value: 'matrix'. Located at position 1 within expression: matrix.shell_name

 

 

Is there a way to use matrix to specify the shell to be used?

 

2 Replies
Solution
GitHub Partner
Message 2 of 3

Re: Using matrix to specify shell: is it possible?

I’m afraid matrix job does not support to set shell as configuration options for a GitHub virtual environment. On Windows, it always uses pwsh to run the commands by default, if you do not specify the shell on the steps.

Copilot Lvl 2
Message 3 of 3

Re: Using matrix to specify shell: is it possible?

Thanks for the quick reply, @BrightRan!

 

I wanted to test my PowerShell module both on PowerShell and on PowerShell Core, and using matrix would have lead to a smaller workflow file.

Not a huge problem, though.