Conditional Services in a job

We have integration tests that work with a matrix of databases. We use the GitHub CI services feature to launch databaes to integration test against. However there are two problems:

  1. Some tests do not need a database service (e.g. sqlite)
  2. All services are launched for each matrix item. E.g. postgresql + mysql + redis are launched for every test in the matrix. But that is wasteful. We only need the database service corresponding to the case in the matrix.

How can this be achieved? So far I’ve seen how we can use the “incude” feature of matrix configuration. However that doesn’t help the first problem where we would want NO database service at all.

1 Like

I’m not aware of any conditional on the services section, but you can just start the service you actually need in a step. If you attach it to the network given by the effect should be basically the same.

Thanks we will try this

1 Like

Can you show an example of YAML config doing that?

I’m wondering about docker layer caching…

Here’s a small example:

One catch I noticed is that is empty if you don’t use any job-level service or container, if you want to manage all services manually just create your own network. :wink: