Declaring a default shell and environment variables across all steps in a job (GitHub Actions)

In a GitHub Actions workflow, is there a way to set defaults that are applied to all steps of a job? Namely, instead of specifying the shell for each step like this:

jobs:
  example:
    steps:
    - run: echo 'hi'
      shell: zsh {0}

I’d like to specify the default shell in a job-wide manner, perhaps like this:

jobs:
  example:
shell: zsh {0}
    steps:
    - run: echo 'hi'

The above syntax doesn’t work, but is there another way to achieve job-wide defaults?

In addition to specifying the shell, I’d also like to specify job-wide environment variables. Typically I’d do this with BASH_ENV, but it wasn’t defined in the CI environment I was using (macOS, specifically).

10 Likes

use defaults
Example

name: my workflow
on: push

jobs:
  build:
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: bash
    
    strategy:
      matrix:       
        os: [windows-latest, ubuntu-latest]
 # environment variables across all steps in a job 
     env:
       VERSION: '1.2.3'   

Github runners will use bash shell in all matrix OS even windows (bash of git will be used).

1 Like