Kubernetes agent does not inherit from default pod template

Hi, trying to inherit container/pod configuration from default global template (kubernetes clouds config) in a declarative pipeline I got following results:

Using yaml with unexpected results:

  • environment variables aren’t inherited from global pod templates
  • resources aren’t inherited from global pod template

Using deprecated containerTemplate works:

  • environment variables are inherited from global pod templates
  • resources are inherited from global pod templates

But for both variants, the volume mounts defined globally in default pod template are inherited.

The documentation says:
Note that it was previously possible to define containerTemplate but that has been deprecated in favor of the yaml format.

I’m really confused, containerTemplate is the only config that works as expected but is deprecated since more than 2 years.

So has anybody an idea how to setup a declarative pipeline with inherited container config which will still work in the future (not deprecated)?

At the end I successfully passed globally defined environment variables in Jenkins to containers by mapping the values in pipeline environment:

pipeline {
   agent {
      kubernetes {
          ...
      }
   }
   environment {
      HTTPS_PROXY="${HTTPS_PROXY}"
      HTTP_PROXY="${HTTP_PROXY}"
      NO_PROXY="${NO_PROXY}"
   }
   stages {
      stage ("build") {
         container("nodejs"){
            //env.HTTPS_PROXY available
   }
}

Good advices in working with pod templates can be found in this article:

But sometimes you don’t get around defining values globally, e.g. http proxy.

Hopefully this helps people searching undocumented features like this.

1 Like

Hello @jaunusa and welcome to this community :wave: .

Thanks a lot for your feedback, that will help others facing the same problem in the future. :+1: