Shared configuration

How to keep your pipelines DRY

After creating several pipelines in Codefresh you will start to notice several common values between them. Common examples are access tokens, environment urls, configuration properties e.t.c.

Codefresh allows you to create those shared values in a central place and then reuse them in your pipelines avoiding the use of copy-paste.

You can share:

  • Environment parameters (easy)
  • Helm values (easy)
  • Any kind of YAML data (advanced)

Creating shared configuration

From the left sidebar click Account settings to enter your global settings. Then choose Shared Configuration from the left menu.

Creating shared configuration snippets

Creating shared configuration snippets

You can create two types of shared configuration:

  • Shared configuration/ Shared secret
  • yaml/ secret yaml

The shared configuration is for environment variables. The secret variant is the same thing but with encrypted values for sensitive data (such as access tokens).

The shared yaml is for Helm value or any other generic information. The secret yaml encrypts the contents.

You can create as many shared snippets as you want (with unique names).

Using shared environment variables

Each pipeline has a set of environment variables that can be defined in its configuration screen.

Pipeline environment variables

Pipeline environment variables

To use your shared configuration, click the import button and select the snippet from the list:

Importing shared configuration

Importing shared configuration

Once you click Select the values from the shared configuration will be appended to the ones you have in your pipelines. In case of similar values the shared configuration will follow the precedence rules.

Using shared Helm values

To use a shared YAML snippet for Helm values you can install a new Helm chart either from

In both cases, when you see the Helm installation dialog you can import any of your YAML snippets to override the default chart values.

Importing Helm values

Importing Helm values

From the same dialog you can also create a brand new shared configuration snippet of type YAML. Not only it will be used for this Helm chart, but it will be added in your global shared configuration as well.

Sharing any kind of YAML data in pipelines

All the snippets from shared configuration are also available as context in the Codefresh CLI

This means that you can manipulate them programmatically and read their values in the pipeline in any way you see fit.

If for example you have a shared configuration named my-global-config you can easily read its contents programmatically using the CLI:

$codefresh get context my-global-config --output=yaml

apiVersion: v1
kind: context
metadata:
  default: false
  system: false
  name: my-global-config
type: config
spec:
  type: config
  data:
    foo: bar

Example - custom value manipulation

Let’s say that you have a YAML segment with the following contents:

favorite:
  drink: coffee
  food: pizza

Here is a pipeline step that is reading the yaml snippet and extracts a value

YAML

version: '1.0'
steps:
 MyFavoriteFoodStep:
    title: Favorite food
    image: codefresh/cli
    commands:
      - echo I love eating $(codefresh get context my-food-values --output=json | jq -r '.spec.data.favorite.food')

Once the pipeline runs, you will see in the logs:

I love eating pizza