question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unrecognized named-value: 'matrix' in job if conditional

See original GitHub issue

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.

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:open
  • Created a year ago
  • Reactions:23
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
markstijnman-shellcommented, 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 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:

on:
  workflow_call:
    inputs:
      build-win32:
        required: true
        type: boolean
      
jobs:
  build:
    strategy:
      matrix:
        include:
          - os: windows-latest
            arch: "win64"
            build: true
          - os: windows-latest
            arch: "win32"
            build: ${{ inputs.build-win32 }}
          - os: ubuntu-latest
            build: true
        
    if: ${{ matrix.build }}
    runs-on: ${{ matrix.os }}

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.

3reactions
AlexandreBrgcommented, Jul 20, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use matrix as a condition in an if statement ...
I want to use a loop like below, but the if's condition has ${{ matrix.project }} doesn't seem to work. The error message...
Read more >
Computing a GitHub Action matrix with cog
I wanted to make the architectures a third axis, but couldn't figure out how to use the YAML syntax to limit the choices...
Read more >
TLC Error Handling - MATLAB & Simulink
To report an error condition detected in your TLC code, ... Value) == "Matrix" %% exit if the parameter is a true matrix,...
Read more >
How to Use the GitHub Actions Matrix Strategy in ...
Learn how to use the GitHub Actions Matrix deployment strategy and take your actions to the next level in this ATA Learning tutorial....
Read more >
LLVM Language Reference Manual
Abstract¶. This document is a reference manual for the LLVM assembly language. LLVM is a Static Single Assignment (SSA) based representation that provides ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found