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

15 views
Skip to first unread message

askannon@flexarc.com (JIRA)

unread,
Feb 22, 2018, 12:04:03 PM2/22/18
to jenkinsc...@googlegroups.com
Thorsten Kunz created an issue
 
Jenkins / Bug JENKINS-49700
nested pod template in library doesn't work as documented
Issue Type: Bug Bug
Assignee: Carlos Sanchez
Components: kubernetes-plugin
Created: 2018-02-22 17:03
Environment: kubernetes-plugin v1.3.1
jenkins: 2.89.4
Priority: Minor Minor
Reporter: Thorsten Kunz

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

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

jenkins-ci@carlossanchez.eu (JIRA)

unread,
Feb 23, 2018, 3:01:03 AM2/23/18
to jenkinsc...@googlegroups.com
Carlos Sanchez commented on Bug JENKINS-49700
 
Re: 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

askannon@flexarc.com (JIRA)

unread,
Feb 23, 2018, 5:15:02 AM2/23/18
to jenkinsc...@googlegroups.com

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.

amith1893@gmail.com (JIRA)

unread,
Jul 5, 2018, 6:22:02 PM7/5/18
to jenkinsc...@googlegroups.com

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 ?

 

 

This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

ashok.mohanty@oracle.com (JIRA)

unread,
Oct 11, 2018, 5:10:04 AM10/11/18
to jenkinsc...@googlegroups.com

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 !!

 

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

fnasser@redhat.com (JIRA)

unread,
Feb 11, 2019, 3:37:02 PM2/11/19
to jenkinsc...@googlegroups.com

Thorsten Kunz 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.

jglick@cloudbees.com (JIRA)

unread,
Jul 16, 2019, 3:43:41 PM7/16/19
to jenkinsc...@googlegroups.com
Jesse Glick assigned an issue to Unassigned
 
Change By: Jesse Glick
Assignee: Carlos Sanchez

fnasser@redhat.com (JIRA)

unread,
Jul 16, 2019, 3:56:02 PM7/16/19
to jenkinsc...@googlegroups.com

fnasser@redhat.com (JIRA)

unread,
Jul 16, 2019, 3:57:01 PM7/16/19
to jenkinsc...@googlegroups.com
 
Re: nested pod template in library doesn't work as documented

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

s+jenkins@wbtf.me (JIRA)

unread,
Oct 4, 2019, 5:21:03 PM10/4/19
to jenkinsc...@googlegroups.com

Thorsten Kunz any update?

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages