Skip to content
Latchkey

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

Run this faster and cheaper on Latchkey managed runners. Start free →