Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-67709

POD inheritance in declarative Pipeline documentation unclear

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • kubernetes-plugin
    • None

      Consulting the kubernetes plugin readme you'll find the following statements
      ...

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

      ...
      and
      ...

      Unlike scripted k8s template, declarative templates do not inherit from parent template. Since the agents declared at stage level can override a global agent, implicit inheritance was leading to confusion.

      You need to explicitly declare the inheritance if necessary using the field inheritFrom.

      In the following example, nested-pod will only contain the maven container.

      ...
      In the following there's an example about where there's no inheritance happening. But there's no single example about how to use inheritFrom with declarative Pipeline.
      Tried to define a name for the outer POD to inherit from using several different things, but seems like I did not find the right place to do so.

      Please improve the documentation making it more clear about how to use this feature (if it is supposed to work).

          [JENKINS-67709] POD inheritance in declarative Pipeline documentation unclear

          curdin added a comment - - edited

          I'm struggling with the same lack of clarity about inheritance in the documentation.

          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 templates

          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. For sure it is a pain merging all the templates/yamls, but it is also pain trying to find out what works and will work in the future.

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

           

          curdin added a comment - - edited I'm struggling with the same lack of clarity about inheritance in the documentation. 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 templates 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. For sure it is a pain merging all the templates/yamls, but it is also pain trying to find out what works and will work in the future. So has anybody an idea how to setup a declarative pipeline with inherited container config which will work in the future (not deprecated)?  

          curdin added a comment -

          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:
          https://docs.cloudbees.com/docs/cloudbees-ci-kb/latest/cloudbees-ci-on-modern-cloud-platforms/understanding-pod-template-inheritance

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

          Hopefully this helps people searching undocumented features like this. 

          curdin added a comment - 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: https://docs.cloudbees.com/docs/cloudbees-ci-kb/latest/cloudbees-ci-on-modern-cloud-platforms/understanding-pod-template-inheritance But sometimes you don't get around defining values globally, e.g. http proxy. Hopefully this helps people searching undocumented features like this. 

            Unassigned Unassigned
            macdrega Joerg Schwaerzler
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: