GitHub Actions: Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.API_KEY
You used an expression context (secrets, env, matrix, steps…) in a place of the workflow where that context is not available.
Unrecognized named-valueUnrecognized named-value: 'secrets'Unrecognized named-value: 'env'Unrecognized named-value: 'matrix'Located at position 1 within expression Meaning
Each workflow key allows only some contexts. secrets cannot be used in a job-level if:; env cannot be used in runs-on; steps is not available in jobs.<id>.if. Move the check into a step, use needs/outputs, or copy the value to an env first.
Common causes
secrets.*used in a job-levelif:env.*used inruns-onorusesmatrix.*used outside the job that defines the matrixsteps.*referenced from another job instead ofneeds.<job>.outputs- Typo in the context name (
secretvssecrets)
⚡ Quick fix
- Check the "Context availability" table for that key in the docs
- Put the condition on a step, or expose the value via
env:/outputs: - Use
needs.<job>.outputs.<name>to read values from another job
Detailed fix by platform
GitHub Actions
- Pass the secret to a step through env and test it there:
env: HAS_KEY: ${{ secrets.API_KEY != '' }}thenif: env.HAS_KEY == 'true'on a step
Code examples
Context availability
jobs:
deploy:
runs-on: ubuntu-latest
# if: secrets.API_KEY != '' # Unrecognized named-value: 'secrets'
steps:
- name: Deploy
if: env.HAS_KEY == 'true'
env:
HAS_KEY: ${{ secrets.API_KEY != '' }}
run: ./deploy.shHow to diagnose
- Key — Which workflow key holds the expression?
- Context — Which context is named?
- Docs — Is it allowed there?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- API rate limit exceeded GitHub Actions: HttpError: API rate limit exceeded for installation ID 123456 / secondary rate limit
- Cache not found / Unable to reserve cache GitHub Actions: Cache not found for input keys: npm-Linux-abc123 / Failed to save: Unable to reserve cache with key, another job may be creating this cache
- Context access might be invalid GitHub Actions: Context access might be invalid: AWS_ACCESS_KEY_ID (editor warning for secrets/vars)
Most viewed in CI/CD
- The process '/usr/bin/git' failed with exit code 128 GitHub Actions: Error: The process '/usr/bin/git' failed with exit code 128
- This job is stuck because you don't have any active runners GitLab CI: This job is stuck because you don't have any active runners online or available with any of these tags assigned to them
- Resource not accessible by integration GitHub Actions: Error: Resource not accessible by integration (403)
Other ways to find it
Where this error sits
Origin: Build & delivery. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 25 Oct 2026