How to Use a Context for Secrets in CircleCI
A context is an org-level secret bundle that workflows attach to specific jobs.
Create a context in org settings, add environment variables to it, then reference it on the job in the workflow so its values appear as env vars.
Attach a context to a job
The context env vars are injected into the job at runtime.
.circleci/config.yml
version: 2.1
workflows:
deploy:
jobs:
- publish:
context:
- prod-secrets
jobs:
publish:
docker:
- image: cimg/node:20.11
steps:
- checkout
- run: npm publish --token "$NPM_TOKEN"Notes
- Restrict a context with a security group so only certain teams can run jobs that use it.
- Contexts beat per-project env vars when many repos share the same credential.
- Combine multiple contexts on one job to layer org-wide and team-specific secrets.
Related guides
How to Run on a Self-Hosted Runner in CircleCIRun a CircleCI job on your own self-hosted runner by targeting a resource class with the machine executor, so…
How to Approve a Production Deploy in CircleCIGate a production deploy in CircleCI with a manual approval job, so the deploy waits for a human click in the…