Is it possible to detect which OS a Github actions runner is using? For example, in node one can run process.platform
to get the OS. Is there something analogous inside of Github actions?
There is an environment variable $RUNNER_OS
containing the operating system; you can specify the shell for a run:
independent of the runner operating system, i.e., you can use Bash everywhere.
For example, this workflow
name: OS test
on:
workflow_dispatch:
jobs:
printos:
name: Print OS name for each OS
strategy:
matrix:
os:
- ubuntu-20.04
- windows-2022
- macos-11
runs-on: ${{ matrix.os }}
steps:
- name: Print OS name
shell: bash
run: |
echo "$RUNNER_OS"
produces three jobs, with outputs Linux
, Windows
, and macOS
, respectively.
The value is also available in the runner
context, which can be used in, e.g., if
conditionals:
- name: Windows-specific step
if: runner.os == 'Windows'
shell: bash
run: |
echo "I am a Windows runner!"