How can I reduce redundancy when using Contexts?

When env variables are configured for a project they can be accessed anywhere in the project. This is unfortunately not the case for contexts. You have to specify the context required for each job individually. If you have a lot of jobs that use this context this creates a lot of redundancy. Ex:
workflows:
build:
jobs:
- job1
context:
- dockerhub-creds
- job2
context:
- dockerhub-creds
- job3
context:
- dockerhub-creds
- job4
context:
- dockerhub-creds

Can we optionally allow contexts to apply to all jobs in a workflow to avoid this? Thanks!

Hi Stephen,

Welcome to CircleCI Discuss!

Currently, there is no way to configure workflows or pipelines this way. Also, I could not find a feature request for this, so please feel free to create one on our idea page under “Cloud Feature Requests”. A good title for this would be along the lines of “Pipeline Level Contexts” or “Workflow Level Contexts” depending what you feel fits your request best. Pipeline level would be for the entire configuration, while workflow level would probably be more realistic.

For now, you could use a built-in functionality of YAML, which are anchors and aliases. At the top of your configuration (or anywhere you find suitable) you could define a custom block that you could reuse anywhere in your configuration.

default-context: &default-context
  context:
    - dockerhub-cred
...
jobs:
   - test2:
       *default-context

That at least reduces the two lines down to one, but still isn’t exactly the best case. Another option would be to implement the dockerhub-creds into the environment variable for that project. Let me know if you create the feature request and I will happily support it!