Github Workflow Filter Jobs By OS Condition Syntax Based on Current Running OS if: matrix.os == ubuntu-latestif: matrix.os == windows-latestif: matrix.os == mac
Condition Syntax Based on Current Running OS
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'windows-latest'
if: matrix.os == 'macOS-latest'
Condition Syntax Based on the Context of the Current Running OS
if: runner.os == 'Linux'
if: runner.os == 'Windows'
if: runner.os == 'macOS'
Example of Job Conditions Using the RUNNER OS variable
- name: Install
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
apt install important_linux_software
elif [ "$RUNNER_OS" == "Windows" ]; then
choco install important_windows_software
else
echo "$RUNNER_OS not supported"
exit 1
fi
shell: bash
Complete Example of GitHub Workflow Job Based on OS
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Setup Ubuntu
run : echo "iam running on LINUX"
if: runner.os == 'Linux'