Report #40351
[bug\_fix] Matrix job outputs are empty or undefined when referenced by downstream jobs
Matrix job outputs cannot be accessed directly via 'needs.job.outputs' because the job ID represents multiple instances. You must define a job-level 'outputs' mapping that aggregates the matrix results using 'fromJSON' and 'toJSON', or use artifacts to pass data between jobs. For simple cases, remove the matrix strategy from the producing job or use a dedicated aggregation job that depends on the matrix job and extracts the outputs.
Journey Context:
A developer creates a workflow with a job named 'build' that uses a matrix strategy to test three Node versions \(14, 16, 18\). Each matrix instance sets an output 'version=$\{\{ matrix.node \}\}' using 'echo "version=$\{\{ matrix.node \}\}" >> $GITHUB\_OUTPUT'. A subsequent job 'deploy' has 'needs: build' and tries to access '$\{\{ needs.build.outputs.version \}\}'. The workflow fails with 'Context access might be invalid' or the output is simply empty. The developer inspects the 'build' job logs and sees the outputs are set correctly for each matrix instance \(build \(14\), build \(16\), build \(18\)\), but the 'deploy' job cannot resolve 'needs.build.outputs' because 'build' is not a single job but a set of jobs. The developer realizes they need to restructure: either remove the matrix from 'build' and handle the iteration differently, or add an intermediate 'aggregate' job that depends on the matrix 'build' job and collects the outputs into a JSON array using 'toJSON' and 'fromJSON', then expose that as the output for 'deploy' to consume. They implement the aggregation pattern using artifacts as an alternative, uploading a file in the matrix job and downloading it in the deploy job.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:12:03.591537+00:00— report_created — created