Can I set a runs-on label for a self-hosted runner using a matrix property?

So if I have a job that I want to build on self-hosted runners, both on java 8 & java 11 (using dedicated machines per jdk), can I use the matrix values in the runs-on property to do this, something like below? 

Runners & their labels:

1. self-hosted, linux, x64, jdk8
2. self-hosted, linux, x64, jdk11
3. self-hosted, windows, x64, jdk8
4. self-hosted, windows, x64, jdk11

And a matrix configuration like so:

runs-on: [self-hosted, ${{ matrix.os }}, x64, jdk${{ matrix.java }}]
    strategy:
      matrix:
        os: [linux, windows]
        java: [8, 11]

Is such a configuration possible? It seems I can use matrix versions as a single runs-on value, like this:

runs-on: ${{ matrix.os }}

However I can’t seem to use that with multiple labels (i.e. ensuring it runs on a self-hosted runner)?

runs-on: ${{ matrix.os }}
strategy:
  matrix:
    os: [self-hosted, linux, windows]
    java: [8, 11]

 Have you tried something like this?

@luisfavila wrote:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [self-hosted, linux, windows]
java: [8, 11]

 Have you tried something like this?

That starts up 6 jobs:

self-hosted, 8
self-hosted, 11
linux, 8
linux, 11
windows, 8
windows, 11

Hi @johnlbergqvist ,

‘run-on’ only accpets hosted runner labels(eg: ubuntu-latest…) and self-hosted runner labels(self-hosted, Windows…).

You can add a custom label for self-hosted runners, and use matrix as below, it will create 4 jobs.

runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [linuxvm, windowsvm] # linux vm is the customer label for self-hosted linux runner, similar for windowsvm.
        java: [8, 11]

Or you can remove jdk from run-on.

runs-on: [self-hosted, '${{ matrix.os }}', X64]
    strategy:
      matrix:
        os: [Linux, Windows]
        java: [8, 11]

matrixjob.png

Thanks.

edited- add screenshot

But how do I ensure that the java 8 builds only start on the machines with the jdk8 label, and the same for jdk11?

Hi @johnlbergqvist,

Thanks for your reply.
Image you have two self-hosted runners with below labels:

  1. self-hosted, Linux, X64, jdk8
  2. self-hosted, Windows, X64, jdk11

You can add ‘include’ parameter to matrix setting, ensure specific java version applied to specific runner. Code sample as below:

on: [push]
jobs:
  job1:
    runs-on: [self-hosted, '${{ matrix.os }}', X64, 'jdk${{ matrix.java }}'] 
    strategy:
      matrix:
        os: [Linux, Windows]
        include: 
          - os: Linux                # limit java8 to self-hosted runner with custom label 'Linux'
            java: 8
          - os: Windows
            java: 11            # limit java11 to self-hosted runner with custom label 'Windows'
    steps:
      - uses: actions/checkout@v2
      - name: Setup java
        uses: actions/setup-java@v1
        with:
          java-version: ${{ matrix.java }}    # it will use specific java version according to the matrix setting.

Thanks