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

nested pod template in library doesn't work as documented

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • kubernetes-plugin
    • None
    • kubernetes-plugin v1.3.1
      jenkins: 2.89.4

      If I setup a external library for different pod templates and use them also as documented it doesn't work:

      Here is the library:

      #!groovy
      package myjenkins
      
      public void mavenTemplate(body) {
      	podTemplate(label: label,
      	containers: [
      		containerTemplate(name: 'maven', image: 'maven:3.5.2-jdk-8', command: 'cat', ttyEnabled: true)
      	],
      	volumes: [
      		secretVolume(secretName: 'maven-settings', mountPath: '/root/.m2'),
      		persistentVolumeClaim(claimName: 'maven-local-repo', mountPath: '/root/.m2nrepo')
      	]) { body() }
      }
      
      public void helmTemplate(body) {
      	podTemplate(label: label,
      		containers: [
      			containerTemplate(name: 'helm', image: 'lachlanevenson/k8s-helm:latest', command: 'cat', ttyEnabled: true)
      		],
      		volumes: []) { body() }
      }
      

      and here is the Jenkinsfile:

      @Library('myjenkins')
      import myjenkins.PodTemplates
      
      label = "worker-${UUID.randomUUID().toString()}"
      
      slaveContainers = new PodTemplates();
      slaveContainers.mavenTemplate {
          slaveContainers.helmTemplate {
      
              node(label) {
                  def myRepo = checkout scm
                  def gitCommit = myRepo.GIT_COMMIT
                  def gitBranch = myRepo.GIT_BRANCH
                  def shortGitCommit = "${gitCommit[0..10]}"
                  def previousGitCommit = sh(script: "git rev-parse ${gitCommit}~", returnStdout: true)
          
                  stage('Test') {
                      try {
                          container('maven') { sh """
                              pwd
                              echo "GIT_BRANCH=${gitBranch}" >> /etc/environment
                              echo "GIT_COMMIT=${gitCommit}" >> /etc/environment
                              mvn -B test
                              """ }
                      }
                      catch (exc) {
                          println "Failed to test - ${currentBuild.fullDisplayName}"
                          throw(exc)
                      }
                  }
                  stage('Build') {
                      container('maven') { sh "mvn -B package" }
                  }
                  stage('Run helm') {
                    container('helm') {
                      sh "helm list"
                    }
                  }
              }
          }
      }
      

      This will result in the following error:

      [Pipeline] End of Pipeline
      groovy.lang.MissingPropertyException: No such property: label for class: com.masergy.jenkins.PodTemplates
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
      

      This all works when I define the podTempaltes directly in the Jenkinsfile so I am pretty sure the plugin itself is setup correctly.
      I just don't know enough about Groovy to fix this issue myself so maybe somebody could fix the documentation so that it works as documented?

      Thanks

          [JENKINS-49700] nested pod template in library doesn't work as documented

          This started happening in 1.1.4 based on JENKINS-49366.
          The agreement seems to be that templates are not related to each other unless using inheritFrom
          Docs need to be updated

          Carlos Sanchez added a comment - This started happening in 1.1.4 based on JENKINS-49366 . The agreement seems to be that templates are not related to each other unless using inheritFrom Docs need to be updated

          Thorsten Kunz added a comment -

          Are there any plans to fix the support for nested templates again? Specifically for the use in shared libraries this is an incredibly useful feature. You can just create a "standard" set of templates and then mix/match them easily in the Jenkinsfiles.

          Thorsten Kunz added a comment - Are there any plans to fix the support for nested templates again? Specifically for the use in shared libraries this is an incredibly useful feature. You can just create a "standard" set of templates and then mix/match them easily in the Jenkinsfiles.

          Amith Gopal added a comment -

          I am currently using Jenkins 2.117, Kubernetes plugin 1.3.1 and  I have done something very similar to what is mentioned and I am getting the same error. Is the creation of a shared library for a pod template supported in Kubernetes plugin 1.3.1 ?

           

           

          Amith Gopal added a comment - I am currently using Jenkins 2.117, Kubernetes plugin 1.3.1 and  I have done something very similar to what is mentioned and I am getting the same error. Is the creation of a shared library for a pod template supported in Kubernetes plugin 1.3.1 ?    

          ASHOK MOHANTY added a comment -

          We are seeing similar issues in Jenkins v.2.121.3 (& JDK 1.8.0_181) with Kubernetes plugin 1.1.4 and 1.12.4.

          getting this bellow ERROR:

          java.io.IOException: container [dind-1] does not exist in pod ........

          Related one could be : JENKINS-50207. Can you please confirm !!

           

          ASHOK MOHANTY added a comment - We are seeing similar issues in Jenkins v.2.121.3 (& JDK 1.8.0_181) with Kubernetes plugin 1.1.4 and 1.12.4. getting this bellow ERROR: java.io.IOException: container [dind-1] does not exist in pod ........ Related one could be :  JENKINS-50207 . Can you please confirm !!  

          askannon try changing this line

          slaveContainers.helmTemplate {

          to

          slaveContainers.helmTemplate { label ->

          You must use the innermost generated label in order get a node which has all the outer pods available on the node.

          Fernando Nasser added a comment - askannon try changing this line slaveContainers.helmTemplate { to slaveContainers.helmTemplate { label -> You must use the innermost generated label in order get a node which has all the outer pods available on the node.

          askannon can you confirm (or not) that the change above solves your problem?

          Fernando Nasser added a comment - askannon can you confirm (or not) that the change above solves your problem?

          askannon any update?

          Wanderley Teixeira added a comment - askannon any update?

            askannon Thorsten Kunz
            askannon Thorsten Kunz
            Votes:
            1 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated: