Environment secret not loaded without declaring environment in CI
Secrets scoped to a deployment environment are only injected into a job that declares environment: <name>. A job that reads such a secret without declaring the environment gets an empty value.
What this error means
A secret that exists under an environment resolves to empty in a job, and that job has no environment: key, so it never gained access to environment-scoped secrets.
# secret PROD_API_KEY is defined on the "production" environment
jobs:
deploy:
# missing: environment: production
steps:
- run: echo "${{ secrets.PROD_API_KEY }}" # -> emptyCommon causes
The job does not declare the environment
Environment secrets load only for jobs that set environment:; without it the secret is out of scope and empty.
The secret exists only at environment scope
There is no repo- or org-level fallback for that name, so a job outside the environment sees nothing.
How to fix it
Declare the environment on the job
- Add
environment: <name>to the job that needs the secret. - Confirm the secret is defined on that environment.
- Re-run; the secret now loads for the job.
jobs:
deploy:
environment: production
steps:
- run: ./deploy.sh
env:
API_KEY: ${{ secrets.PROD_API_KEY }}Promote the secret if it is not environment-specific
If the value is not tied to an environment gate, define it at repository or org level so any job can read it.
# Settings > Secrets and variables > Actions > Repository secretsHow to prevent it
- Declare
environment:on jobs that use environment secrets. - Keep environment-only secrets for environment-gated jobs.
- Use repo/org secrets for values needed everywhere.