In a gitlab pipeline, I can specify a job like:
build:
parallel:
matrix:
- architecture: [x86_64, arm]
operating_system: [linux, macos]
And that will create 4 separate jobs that can all run in parallel:
build [x86_64, linux]
build [x86_64, macos]
build [arm, linux]
build [arm, macos]
I can also specify another job like:
test:
needs:
- job: build
parallel:
matrix:
- architecture: [x86_64, arm]
operating_system: [linux, macos]
And that would create one more job named test
that would wait for all 4 build
jobs to run before starting.
But what If I wanted 4 separate test
jobs, one for each combo of architecture
and operating_system
, just like the build
jobs? I would want something like:
test:
parallel:
matrix:
- architecture: [x86_64, arm]
operating_system: [linux, macos]
needs:
- job: build
parallel:
matrix:
- architecture: [x86_64, arm]
operating_system: [linux, macos]
But, I'm assuming that would create 4 separate test
jobs that would each depend on all of the 4 separate build
jobs. What I'd want is for each of the test
jobs to only depend on a single build
job with the same variables. In the past, I've tried to use variables in the needs
array, but this was before needs:parallel:matrix
was introduced, and it didn't work anyway. Can you use variables in needs:parallel:matrix
to achieve this? Something like:
test:
parallel:
matrix:
- architecture: [x86_64, arm]
operating_system: [linux, macos]
needs:
- job: build
parallel:
matrix:
- architecture: [$architecture]
operating_system: [$operating_system]
Edit: This is not even close to the suggested duplicate. That one is about letting individual jobs only be dependent on other single jobs rather than entire stages being dependent on entire previous stages. That issue can be solved by simply using the needs
keyword which was introduced in gitlab 12.2, as noted in the responses to that question. My question is about parallel:matrix
(introduced in gitlab 15.9) and needs:parallel:matrix
(introduced in gitlab 16.3). These are more advanced directives.
needs:
. So the proposed solution won't work. – Ingoldparallel:matrix
andneeds:parallel:matrix
didn't even exist. – Ingold