Unrecognized named-value: 'matrix' in job if conditional
See original GitHub issueDescribe the bug
A job generates a matrix as an output and I have a subsequent job that depends on the generation of that matrix. The first job does an API call to get all customers which each have a unique schema association. I only want to run this second job in the event that my input SCHEMA array contains the schema of a given return record. However, when I execute the build I get the following error: Unrecognized named-value: 'matrix'. Located at position 26 within expression: contains(inputs.SCHEMAS, matrix.customer.schema)
. The pattern works without the conditional, but does not fit my use case.
This is a rough idea of what the job looks like.
job-name:
runs-on: ubuntu-latest
needs: get-customers
if: contains(inputs.SCHEMAS, matrix.customer.schema)
strategy:
matrix:
customer: ${{fromJson(needs.get-customers.outputs.customers)}}
steps:
....
Expected behavior The job should only run when the matrix schema is contained within the input SCHEMA
Runner Version and Platform
ubuntu-latest
What’s not working?
The use of matrix
in a job level conditional
Issue Analytics
- State:
- Created a year ago
- Reactions:23
- Comments:12 (2 by maintainers)
I ran into this issue today as well. Can the matrix context indeed be added to
jobs.<job_id>.if
? I would imagine that if it is available forruns-on
, it should be possible to make it available forjobs.<job_id>.if
too, as I would expect both are evaluated before starting the job.My use case is in reusable workflows, where I also want to reuse my matrix for several projects, However, there are projects who don’t need all configurations. So I want to allow the calling workflow to use input parameters to skip certain matrix entries. For example, I would very much like something like this to work, which would allow the calling workflow to control whether to build for win32:
I’ve seen workarounds that use a separate job to set up a matrix, but that solution is (1) much harder to understand than this one, and (2) will introduce an extra job in your output that is just noise.
I had the same issue, it seems that
if
statement is evaluated before running a matrix of jobs. I found this topic on GitHub forum about this problem.