GitHub Actions Secret Empty or "Context access might be invalid"
A secret reference resolves to an empty string because the name is wrong, the secret lives at a scope this job cannot see, or it is referenced where the secrets context is unavailable.
What this error means
A step using secrets.<NAME> behaves as if the value is blank, and downstream auth fails. The editor may warn "Context access might be invalid" for the secret name.
Error: missing API key
# secrets.API_KEY came through empty
Warning: Context access might be invalid: API_KEYCommon causes
Name or scope mismatch
Secret names are case-sensitive and scoped. A repo secret is not visible if the job expects an environment secret, and an org secret may not be shared with this repo.
Referenced where secrets are unavailable
The secrets context is not available in some keys (like runs-on or a reusable-workflow uses line), so the reference silently yields nothing.
How to fix it
Define the secret at the scope the job uses
- Add the secret under the right scope: repo, environment (with environment: set on the job), or org with access to this repo.
- Match the exact case of the secret name.
- For reusable workflows, pass secrets explicitly or with secrets: inherit.
Reference secrets only where allowed
Use secrets in step env or with, not in keys evaluated before the job context exists.
jobs:
deploy:
environment: production
steps:
- run: ./deploy.sh
env:
API_KEY: ${{ secrets.API_KEY }}How to prevent it
- Keep a single, documented scope for each secret.
- Set environment: on jobs that consume environment secrets.
- Forward secrets explicitly to reusable workflows.