How to Set the Default Shell to PowerShell or Bash on Windows in GitHub Actions
On windows-latest, run steps default to PowerShell Desktop; set shell explicitly to pick pwsh, bash, or cmd instead.
Set defaults.run.shell at the workflow or job level, or shell: on a single step. On Windows the choices include pwsh (PowerShell 7), powershell (Windows PowerShell 5.1), cmd, and bash (Git Bash).
Steps
- Set
runs-on: windows-lateston the job. - Add
defaults: { run: { shell: pwsh } }to set the default for every run step. - Override a single step with
shell: bashorshell: cmdwhere needed.
Workflow
.github/workflows/ci.yml
jobs:
build:
runs-on: windows-latest
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v4
- run: $PSVersionTable.PSVersion # runs in PowerShell 7
- run: echo "this step uses bash"
shell: bashGotchas
pwshis PowerShell 7 (cross-platform);powershellis the older Windows PowerShell 5.1.- Without
shell:, Windows run steps default topowershell, which differs frompwshin modules and behavior.
Related guides
How to Run a PowerShell Script Step on Windows in GitHub ActionsRun inline PowerShell or a .ps1 file on a windows-latest runner in GitHub Actions using shell: pwsh, passing…
How to Set PowerShell ErrorActionPreference to Fail on Errors in GitHub ActionsMake PowerShell steps on a windows-latest runner in GitHub Actions fail the build on errors by setting $Error…