Build Environment

Overview

As with pod environment variables, build environment variables can be defined in terms of references to other resources/variables using the Downward API. However, there are some exceptions as noted below.

You can also manage environment variables defined in the BuildConfig with the oc set env command.

Using Build Fields as Environment Variables

You can inject information about the build object by setting the fieldPath environment variable source to the JsonPath of the field from which you are interested in obtaining the value.

  1. env:
  2. - name: FIELDREF_ENV
  3. valueFrom:
  4. fieldRef:
  5. fieldPath: metadata.name

Jenkins Pipeline strategy does not support valueFrom syntax for environment variables.

Using Container Resources as Environment Variables

Referencing container resources using valueFrom in build environment variables is not supported as the references are resolved before the container is created.

Using Secrets as Environment Variables

You can make key values from Secrets available as environment variables using the valueFrom syntax.

  1. apiVersion: v1
  2. kind: BuildConfig
  3. metadata:
  4. name: secret-example-bc
  5. spec:
  6. strategy:
  7. sourceStrategy:
  8. env:
  9. - name: MYVAL
  10. valueFrom:
  11. secretKeyRef:
  12. key: myval
  13. name: mysecret