Basics > Using Contexts
This document describes creating and using contexts in CircleCI in the following sections:
Contexts provide a mechanism for securing and sharing environment variables across projects. The environment variables are defined as name/value pairs and are injected at runtime.
Contexts are created on the Settings page of the CircleCI application, in the Organization section. After a context is set in the application it may be configured in the workflows section of the
config.yml file for a project.
To use environment variables set on the Contexts page, the person running the workflow must be a member of the organization for which the context is set and the rule must allow access to all projects in the org. The default context name is
org-global and the default rule allows access to all projects in the org.
Using a Context
Navigate to the Settings > Contexts page in the CircleCI application. The Create a Context button appears.
Click the Create Contexts button. The default name and rules appear with an Add a Resource button.
Click the Add a Resource button and fill in the variable name and value. Click the Add Variable button to save it.
context: org-globalkey to the
workflowssection of your
config.ymlfile for every job in which you want to use the variable. In the following example, the
run-testsjob will use the variables set in the
workflows: version: 2 my-workflow: jobs: - run-tests: context: org-global
To rerun a job and use the context, it must be rerun from the Workflows page of the CircleCI application. Jobs invoked using the Rebuild button on the Builds page will not use the context defined in the workflow.
Note: Environment variables are considered in a specific order, as follows:
- Project-level environment variables set on the Project Settings page.
- Context environment variables (assuming the user has access to the Context).
- Environment variables set with the
environmentkey of a
- Environment variables declared inside a shell command in a
runstep, for example
FOO=bar make install.
Send Feedback on Contexts
We’re interested in your feedback on how Contexts can evolve. Read more about our proposed roadmap and offer suggestions in the contexts discussion.