Skip to content
Latchkey

CircleCI "Context not found" / Missing Env Var - Fix

A workflow references a context that CircleCI cannot find, or a job runs without the env var you expected because the context was never attached. The values you stored never reach the job.

What this error means

Either validation fails naming a context that "could not be found", or the job runs but a required variable is empty and a later step fails with "command not found" / unauthorized. The secret simply was not injected.

CircleCI UI / job log
Context(s) "aws-prod" not found, or not authorized for this project.
# or, at runtime:
$ aws s3 cp build/ s3://...
Unable to locate credentials. AWS_ACCESS_KEY_ID is empty.

Common causes

Context name typo or wrong case

Context names are exact. AWS-Prod will not match a context named aws-prod, so it resolves to nothing.

Context not created or not shared with the org

The context must exist in the organization that owns the project. A context from another org, or one never created, is invisible to the pipeline.

Context restricted by security group

Restricted contexts only run for members of an allowed group. A fork PR or an unlisted user’s pipeline cannot access them, so the variables stay unset.

How to fix it

Attach the correct context to the job

.circleci/config.yml
workflows:
  deploy:
    jobs:
      - deploy:
          context:
            - aws-prod

Verify the context exists and is shared

  1. Open Organization Settings → Contexts and confirm the exact name and case.
  2. Confirm the context belongs to the org that owns this project.
  3. If it is restricted, confirm the pipeline runs as an allowed user/group.

Assert the variable is present early

Fail fast with a clear message instead of a confusing downstream error.

.circleci/config.yml
- run:
    name: Check creds
    command: '[ -n "$AWS_ACCESS_KEY_ID" ] || { echo "context not attached"; exit 1; }'

How to prevent it

  • Reference contexts by their exact name and keep names lowercase.
  • Store shared secrets in org contexts, not per-project, so they are reusable.
  • Add an early assertion that required env vars are non-empty.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →