GitHub Actions "matrix cannot expand from secrets"
The strategy.matrix is evaluated before a job runs, in a context where the secrets context is not available. Referencing secrets there produces an invalid or empty matrix.
What this error means
A matrix referencing secrets.* fails validation or expands to nothing, so jobs do not run as expected.
github-actions
Error: The workflow is not valid.
Unrecognized named-value: 'secrets'. matrix cannot expand from the secrets context.Common causes
secrets referenced in matrix definition
matrix.include or a matrix vector references secrets.*, which is not resolvable at matrix-expansion time.
How to fix it
Build the matrix without secrets
- Use static values, vars, or a fromJSON of a job output for the matrix.
- Consume secrets inside the job steps (where the secrets context is available), not in the matrix.
.github/workflows/deploy.yml
strategy:
matrix:
target: ${{ fromJSON(needs.setup.outputs.targets) }}
steps:
- run: deploy --token "${{ secrets.DEPLOY_TOKEN }}"How to prevent it
- Keep secrets out of matrix definitions; reference them only inside steps.
- Generate dynamic matrices from a prior job output via fromJSON.
Related guides
GitHub Actions "Unrecognized named-value: secrets"Fix the GitHub Actions expression error "Unrecognized named-value: secrets" caused by using a context where i…
GitHub Actions Dynamic Matrix from fromJSON Fails - Not an ArrayFix GitHub Actions dynamic matrix errors - a matrix built from fromJSON of a job output that is empty, not va…
GitHub Actions matrix produced duplicate combinationsFix a matrix that errors or wastes jobs because include/exclude rules produce duplicate combinations.