Job with dynamic matrix crashes if matrix contains zero elements. How to resolve? #27096
-
Hi all. I have a GitHub action with two jobs. The first job returns an array, which I’ve been able to pass to a second job which then uses that array as its matrix. But the first job can sometimes return an array with zero length, and when it does, the second job crashes with the error:
How can I resolve this? Ideally, if job-1 returns an array with zero elements, the second job would not run at all. I’ve seen this continue-on-error flag, but I’m not sure exactly how to use it. In my case, the crash doesn’t seem to occur on any specific step–it occurs when the job is trying to evaluate the matrix. My Code (myfile.yml)
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Try putting some sort of condition if statement on Job 2, where you do something like: if: ${{ needs.Job-1.outputs.matrix != “” }} something like that. |
Beta Was this translation helpful? Give feedback.
-
OK perfect, thanks–that works! I had found a way to set a condition on a particular step in a job, but didn’t know how to put a conditional on an entire job, which is exactly what I needed. |
Beta Was this translation helpful? Give feedback.
-
Can you share what the if statement looks like? |
Beta Was this translation helpful? Give feedback.
-
It’s essentially what you gave me :slight_smile:
At the same time though, I had to modify the previous job to return an empty string if it would otherwise return an empty array. Previously it would return this string: |
Beta Was this translation helpful? Give feedback.
-
For those looking to prevent builds with empty matrices in the form of empty JSON array's, a conditional in the following form worked for me: if: ${{ needs.some-job.outputs.builds != '[]' }} Where |
Beta Was this translation helpful? Give feedback.
Try putting some sort of condition if statement on Job 2, where you do something like:
if: ${{ needs.Job-1.outputs.matrix != “” }}
something like that.