How do you run a step only on a specific OS in a cross-platform matrix?
BeginnerConceptJobs, Steps, Matrix & Concurrency
Answer
Use the runner context at step level:
- if: runner.os == 'Windows'
shell: pwsh
run: Get-ChildItem env:
- if: runner.os != 'Windows'
run: env | sort
runner.os is Linux, Windows or macOS; runner.arch is X64 or ARM64.
More on Jobs, Steps, Matrix & Concurrency
How does `needs` work, and what happens to a job whose dependency failed or was skipped?BeginnerWhat is the implicit `success()` in a job `if`, and why is `always()` usually the wrong fix?IntermediateWhat values can `needs.<job>.result` take?BeginnerHow does a matrix expand, and how are job names generated?BeginnerHow do `include` and `exclude` work in a matrix?IntermediateWhat do `fail-fast` and `max-parallel` do?Beginner