How can I reduce redundancy when using Contexts?

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!

1 Like