0

I have the need to use environment variables in the POD definition that depend on other declared environment variables. For this to happen correctly, I need the POD resource tobe generated with a specific order of environment variables.

Here is part of my code, as part of Jenkins pipelines, that uses the Jenkins kubernetes plugin:

        Map podTemplate = [
            yamlMergeStrategy: steps.merge(),
            yaml: '''
apiVersion: v1
kind: Pod
spec:
  containers:
    - name: "maven"
      env:

      - name: DD_AGENT_HOST
        valueFrom:
          fieldRef:
            fieldPath: status.hostIP

      - name: DD_ENTITY_ID
        valueFrom:
          fieldRef:
            fieldPath: metadata.uid

      - name: DD_env
        value: eks-ci

      - name: DD_TRACE_AGENT_URL
        value: http://$(DD_AGENT_HOST):8126

However, the POD generated by Jenkins has this order in env vars:

    - name: "DD_TRACE_AGENT_URL"
      value: "http://$(DD_AGENT_HOST):8126"
    - name: "DD_AGENT_HOST"
      valueFrom:
        fieldRef:
          fieldPath: "status.hostIP"

as you can see, the DD_TRACE_AGENT_URL is not resolved correctly to using an actual IP, http://xxx.xxx.xxx.xxx:8126 as it needs to have defined DD_AGENT_HOST above it.

Any ideea on how to make Kubernetes plugin to preserve the order of the env vars, ie the order in the pipelines code to be the same as in final POD generation?

StefanH
  • 799
  • 1
  • 6
  • 22

0 Answers0