Skip to content
Latchkey

How to Run a Batch or cmd Step on Windows in GitHub Actions

Set shell: cmd to run classic batch scripts, and check errorlevel so a nonzero result fails the step.

Use shell: cmd for .bat/.cmd work. GitHub appends an errorlevel check to cmd steps, but for multi-command lines you should still test errorlevel yourself.

Steps

  • Set the step shell: to cmd.
  • Call the script with call build.bat so control returns to the step.
  • Check if %errorlevel% neq 0 exit /b %errorlevel% after risky commands.

Workflow

.github/workflows/ci.yml
jobs:
  build:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run a batch script
        shell: cmd
        run: |
          call scripts\build.bat
          if %errorlevel% neq 0 exit /b %errorlevel%

Gotchas

  • Use call to invoke another .bat, otherwise control does not return and later lines are skipped.
  • cmd does not stop on the first failing command in a multi-line block; check errorlevel explicitly.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →