GitHub Actions strategy matrix objects


This post goes over how to pass objects to GitHub Actions strategy matrix.

Strings

You can pass primitive values to matrix strategy:

jobs:
  example_matrix:
    strategy:
      matrix:
        version: [10, 12]
        os: ['ubuntu-latest', 'windows-latest']

    runs-on: ${{ matrix.os }}
    steps:
      - run: echo ${{ matrix.version }}

Objects

To pass objects to matrix strategy:

jobs:
  example_matrix:
    strategy:
      matrix:
        object:
          [
            { version: 10, os: 'ubuntu-latest' },
            { version: 10, os: 'windows-latest' },
            { version: 12, os: 'ubuntu-latest' },
            { version: 12, os: 'windows-latest' },
          ]

    runs-on: ${{ matrix.os }}
    steps:
      - run: echo ${{ matrix.version }}

Alternatively:

jobs:
  example_matrix:
    strategy:
      matrix:
        object:
          - version: 10
            os: 'ubuntu-latest'
          - version: 10
            os: 'windows-latest'
          - version: 12
            os: 'ubuntu-latest'
          - version: 12
            os: 'windows-latest'

    runs-on: ${{ matrix.os }}
    steps:
      - run: echo ${{ matrix.version }}

See example.



Please support this site and join our Discord!