Skip to content

shell in step/defaults cannot use job/matrix templates #444

Open

Description

@jacekkow

shell parameter in steps context should allow ${{ job/steps. }} variables.
I can see no reason for disallowing such expressions there.

To Reproduce

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
       - run: no matter what
         shell: echo ${{ job.status }}

https://github.com/jacekkow/github-actions-bugs/blob/master/.github/workflows/bug1.yml

Expected behavior
Step returns:

Success

Runner Version and Platform

GitHub Actions

What's not working?

The workflow fails:

The workflow is not valid. .github/workflows/bug1.yml (Line: 9, Col: 17): Unrecognized named-value: 'job'. Located at position 1 within expression: job.status

As far as I can tell this is due to non-empty-string being used instead of string-steps-context (or perhaps new non-empty-string-steps-context?) here:

"shell": "non-empty-string"

Similar change should also be made here:

"shell": "non-empty-string"

Activity

  1. TingluoHuang commented on Apr 22, 2020

    @TingluoHuang
    Member

    Shell is mean to set to ‘cmd’ ‘bash’ ‘sh’ and ‘powershell’
    We do support expressions in the script content

    • run: echo ${{job.status}}
      Shell: bash
  2. jacekkow commented on Apr 22, 2020

    @jacekkow
    Author

    Shell is mean to set to ‘cmd’ ‘bash’ ‘sh’ and ‘powershell’

    Per docs:

    You can use built-in shell keywords, or you can define a custom set of shell options.

    https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell

    So I'm defining custom shell and its options (as documented). I really don't see a reason for "run" accepting expressions and "shell" not.

  3. TingluoHuang commented on Apr 22, 2020

    @TingluoHuang
    Member

    @chrispat for whether we allow expression in script's shell option

  4. chrispat commented on Apr 22, 2020

    @chrispat
    Contributor

    I don't see any reason not to. The only reason we don't allow it is uses is so we can implement policy to prevent running certain actions.

  5. added
    enhancementNew feature or request
    and removed
    bugSomething isn't working
    enhancementNew feature or request
    on Jun 8, 2020
  6. JustinGrote commented on Mar 26, 2021

    @JustinGrote

    @chrispat any update? I want to run Powershell test/builds in matrix and right now I have two very redundant tasks with an if expression gating them.

  7. nikola-jokic commented on Feb 8, 2022

    @nikola-jokic
    Contributor

    Hi @JustinGrote,

    While reproducing this issue, I noticed that shell expression would work now. Could you please tell me if you are still experiencing this issue? If you do, could you provide an example repository so I can reproduce this behaviour with your workflow, so I don't miss anything?

  8. self-assigned this
    on Feb 8, 2022
  9. 5 remaining items

  10. sio commented on Jul 20, 2022

    @sio

    Another example where expressions could be useful in shell:

    I tried to use custom shell with GitHub actions, and installed in previous step. But I can not reference the absolute path with: shell: ${{ github.workspace }}/bin/shell {0} because:

    The workflow is not valid. .github/workflows/test.yml (Line: 77, Col: 16): Unrecognized named-value: 'github'
    
  11. msJinLei commented on Jul 17, 2024

    @msJinLei

    I modifiy the example workflow https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#example-expanding-configurations
    into the following one.
    It reports the same error as above.

    name: Conditional Shell Matrix Workflow
    
    on: [push]
    
    jobs:
      example_matrix:
        strategy:
          fail-fast: false
          matrix:
            os: [windows-latest, ubuntu-latest]
            node: [14, 16]
            include:
              - os: windows-latest
                node: 16
                npm: 6
                shell: powershell
              - os: ubuntu-latest
                shell: bash
        runs-on: ${{ matrix.os }}
        steps:
          - name: Checkout repository
            uses: actions/setup-node@v4
            with:
              node-version: ${{ matrix.node }}
          - name: Install NPM
            if: ${{ matrix.npm }}
            run: |
                npm install -g npm@${{ matrix.npm }}
                npm --version
          - name: Print current working directory
            shell: ${{ matrix.shell }}
            run: |
              echo "The current working directory is $GITHUB_WORKSPACE"
              ls "$GITHUB_WORKSPACE"
    
  12. added a commit that references this issue on Aug 21, 2024
  13. added a commit that references this issue on Sep 30, 2024
  14. jeremyd2019 commented on Jun 19, 2025

    @jeremyd2019
    Contributor

    The https://github.com/cygwin/cygwin-install-action action has an output for the install path, so I reasonably tried to do

          - id: cygwin
            uses: cygwin/cygwin-install-action@master
            with:
              packages: ...
          - name: build
            run: ...
            shell: ${{ steps.cygwin.outputs.root }}\bin\bash.exe -leo pipefail -o igncr '{0}'

    I think this is this same 5-year-old bug?!?

  15. added a commit that references this issue on May 28, 2026
  16. joffrey-bion commented on Aug 10, 2026

    @joffrey-bion

    I'm facing this issue as well. I'm trying to run custom shells so I can test my application with a tty. This is different on different OSes, so I want to use the matrix like this:

    jobs:
      test: 
         ...
      test-jvm-compatibility:
        needs: test
        strategy:
          fail-fast: false
          matrix:
            os: [macos-latest, windows-latest, ubuntu-latest]
            java-version: [17, 21, 25]
            include:
              - os: macos-latest
                shell-with-pty: 'script -q /dev/null bash -c "bash {0}"'
              - os: ubuntu-latest
                shell-with-pty: 'script -q -e -c "bash {0}"'
              - os: windows-latest
                shell-with-pty: 'winpty -Xallow-non-tty bash {0}'
        runs-on: ${{ matrix.os }}
        steps:
          - uses: actions/setup-java@v5
            with:
              distribution: 'temurin'
              java-version: ${{ matrix.java-version }}
          - name: Download R8 Jar
            uses: actions/download-artifact@v6
            with:
              name: main-r8-jar
              path: artifacts
    
          - name: Run R8 Jar without a tty without enable-native-access all-unnamed
            run: java -jar artifacts/main-r8.jar
    
          - name: Run R8 Jar without a tty with enable-native-access all-unnamed
            run: java --enable-native-access=ALL-UNNAMED -jar artifacts/main-r8.jar
    
          - name: Run R8 Jar with a tty without enable-native-access all-unnamed
            shell: ${{ matrix.shell-with-pty }}
            run: java -jar artifacts/main-r8.jar
    
          - name: Run R8 Jar with a tty with enable-native-access all-unnamed
            shell: ${{ matrix.shell-with-pty }}
            run: java --enable-native-access=ALL-UNNAMED -jar artifacts/main-r8.jar

    But I'm getting this like everyone else:

    Invalid workflow file

    (Line: 105, Col: 16): Unrecognized named-value: 'matrix'. Located at position 1 within expression: matrix.shell-with-pty, (Line: 109, Col: 16): Unrecognized named-value: 'matrix'. Located at position 1 within expression: matrix.shell-with-pty

    Is there any chance we could see this implemented soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions