Use services in some jobs of a matrix


I’ve got a complex job, consisting of many steps that I want to run in Linux and Windows. The only difference, besides the OS, is that in Linux there is a step using PostgreSQL, and in Windows this is skipped.

I’m able to have the next configuration yaml, that is exactly what I want, except that the postgres service should not start for Windows, and it does. Not sure if postgres is able to start on windows, but in practice I need more services (MySQL…) and some of them surely fail to start in Windows.

    name: Complex job
    runs-on: ${{ matrix.os }}
        image: postgres:latest
        os: [ubuntu-latest, windows-latest]
      # Lots of steps that I don't want to duplicate

I can make this work if I create two jobs, one for Windows without the services, and one for Linux with the services. But I need to copy the long list of steps, and make all changes twice in the future.

Is there a way to do what I want in a reasonable way?


Thanks for your feedback!

It’s a limitation to use services in some jobs of matrix. ‘jobs.<job_id>.services’ has the same level with jobs.<job_id>.strategy, and it will initialize the container before the steps execution. Please create individul jobs for different runner os.