You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unrecognized named-value: 'matrix' in job if conditional #1985
Describe 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.
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
Reacted by Eugene Kliuchnikov, Joe-Kollin, Alexandre Burgoni, dpc, Guillaume Bonnet, Jun Kitamura, Ingvar Stepanyan, Badisi, Clynt Neiko Rupinta, Andra Gnodtke and 55 more
Same problem here. Are there any plans to add the matrix context to the jobs.<job_id>.if condition?
Reacted by kdkavanagh, wcarpenter1-godaddy, Milos Nikolic, Tomas Sandven, Wahab Alshahin, August, Jason Meridth, Sierra Wendt, Peter Garud and Artemy Pozdnyakov
Obviously with a few more steps than in the above truncated example.
It makes the whole workflow feel a bit messy, especially since the jobs are being marked as successfully run when in reality all the steps within it have been skipped.
(never mind my failed job, it's still in development😅)
Reacted by Timothée Mazzucotelli and Tomas Sandven
@mrkesu: if you're up for it, you should really try having a job that creates your matrix and then have it create an empty array when you don't want it to do work. #1985 (comment)
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 for runs-on, it should be possible to make it available for jobs.<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.
Reacted by Diego García, Mantas Gurskis, Kirill Timchenko, Gurleen Sethi, Kanji Yomoda, Kevin Woo, kdkavanagh, Andrey Helldar, Samuel Baena, Gajo Petrovic and 3 more
It's indeed a bit surprising to get this error when seeing that runs-on works just fine with it:
runs-on: ${{ matrix.os }} # okif: ${{ matrix.os == 'ubuntu-latest' }} # not ok
Reacted by Wahab Alshahin, Krishna Kumar, Peter Garud, James Knight, Tom Daly, Didrik Nordström, Victor Irzak, Róbert Papp, Kris Luminar, Artemy Pozdnyakov and 1 more
Here is the most elegant solution I found to this issue:
jobs:
exclude-jobs:
runs-on: ubuntu-latestoutputs:
jobs: ${{ steps.exclude-jobs.outputs.jobs }}steps:
- id: exclude-jobs# 1. use any other condition(s) that fits your requirements# 2. each item in the JSON array will be matched against your matrix later# 3. here I exclude everything except ubuntu-latest + python3.7 (see matrix below)# 4. make sure to output as single line# 5. the default case is: exclude nothingrun: | if ${{ github.repository_owner == 'pawamoy-insiders' }}; then # 1 # 2, 3 echo 'jobs=[ {"os": "macos-latest"}, {"os": "windows-latest"}, {"python-version": "3.8"}, {"python-version": "3.9"}, {"python-version": "3.10"}, {"python-version": "3.11"} ]' | tr -d '[:space:]' >> $GITHUB_OUTPUT # 4 else echo 'jobs=[]' >> $GITHUB_OUTPUT # 5 fitests:
needs: exclude-jobsstrategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latestpython-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"# simply use the previous JSON data you echoed to exclude jobsexclude: ${{ fromJSON(needs.exclude-jobs.outputs.jobs) }}
Reacted by René Fritze, sandroro, Renato Prado and Amine Bezzarga
I just ran into this issue. As others pointed out, it seems unintuitive that runs-on can access the matrix but if can't. Both proposed workarounds (moving ifs to steps or creating a new job to make the matrix) add a lot of unneeded complexity.
Activity
alexandrebrg commentedon Jul 20, 2022
I had the same issue, it seems that
ifstatement is evaluated before running a matrix of jobs. I found this topic on GitHub forum about this problem.funes79 commentedon Sep 29, 2022
I do have the same issue, and not using any
ifstatement. And the matrix value does not contain any spaces.funes79 commentedon Sep 30, 2022
My bad, that was a typo in the script last line
martixinstead ofmatrix.korewaChino commentedon Oct 7, 2022
Also having this issue. the workflow works fine if there was no if statement.
carmocca commentedon Oct 8, 2022
I also have this problem in Lightning-AI/pytorch-lightning#15043
jsoref commentedon Oct 12, 2022
You can probably work around this by having additional jobs that generate outputs and relying on
needsand theoutputsfrom those jobs.You might need to demote your
ifs from job level to step level.garciasdos commentedon Nov 25, 2022
Same problem here. Are there any plans to add the
matrixcontext to thejobs.<job_id>.ifcondition?mrkesu commentedon Nov 29, 2022
I'm also encountering this issue.
Sadly my workflow had to be changed from this:
to this:
Obviously with a few more steps than in the above truncated example.
It makes the whole workflow feel a bit messy, especially since the jobs are being marked as successfully run when in reality all the steps within it have been skipped.
(never mind my failed job, it's still in development😅)

jsoref commentedon Nov 29, 2022
@mrkesu: if you're up for it, you should really try having a job that creates your matrix and then have it create an empty array when you don't want it to do work. #1985 (comment)
Here's a workflow which does something similar:
https://github.com/commercialhaskell/stack/blob/71a85a488ef458d5c7d315b647411056aafd3d0a/.github/workflows/integration-tests.yml#L104-L127
Split out test jobs
markstijnman-shell commentedon Mar 3, 2023
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>.iftoo, 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.
Dynamic matrix
pawamoy commentedon May 15, 2023
It's indeed a bit surprising to get this error when seeing that
runs-onworks just fine with it:pawamoy commentedon Jun 2, 2023
Here is the most elegant solution I found to this issue:
Gustl22 commentedon Apr 6, 2024
Thanks @pawamoy that worked for me, in order to use a one dimensional set of inputs and rather use
include:excitoon commentedon Apr 27, 2024
@pawamoy @Gustl22 You can also do it this way:
Inside nested job
ifwill work again.https://docs.github.com/en/actions/using-workflows/reusing-workflows#using-a-matrix-strategy-with-a-reusable-workflow
deannagarcia commentedon Jun 14, 2024
I just ran into this issue. As others pointed out, it seems unintuitive that
runs-oncan access the matrix butifcan't. Both proposed workarounds (moving ifs to steps or creating a new job to make the matrix) add a lot of unneeded complexity.Any chance we could see this be added?
Sivakajan-tech commentedon Aug 6, 2024
The 3rd example in the Repo should be useful in conditionally build the matrix in the GitHub Actions.
https://github.com/dorny/paths-filter?tab=readme-ov-file#examples
ci: can't use the matrix strategy for determining which binary to com…
fix(ci): use matrix.isCached check in steps instead of job
ci: cache pnpm store, collapse deploy jobs into a matrix, add og-api/…
ci: cache pnpm store, collapse deploy jobs into a matrix, add og-api/…
fix(ci): validate ci.yml - replace matrix-in-if antipattern with expl…
ci: cache pnpm store, collapse deploy jobs into a matrix, add og-api/…
ci(00.03): conformance matrix job - ubuntu PR+main, macOS main-only