Jenkins can't execute steps in PODs created from a Shared Library

I wrote a very simple Jenkins Library that should execute some stages in a kubernetes POD.

The directory structure is:

├── README.md
├── resources
│   ├── exc
│   │   ├── build.jl
│   │   └── test.jl
│   └── k8s
│       └── my_pod.yaml
├── src
└── vars
    └── package_pipeline.groovy

This is the content of package_pipeline.groovy:

#!/usr/bin/env groovy

def call(String package_dir)
{
    script {
        def pod_yaml = libraryResource "k8s/my_pod.yaml"

        podTemplate(cloud: "my-cloud", namespace: "my-namespace", yaml: pod_yaml) {
            node(POD_LABEL) {
                stage("build") {
                    container('mycontainername') {
                        sh "pwd"
                    }
                }
            }
        }
    }
}

This is the contents of Jenkinsfile in the repo that uses the above library:

#!/usr/bin/env groovy

@Library('julia-jenkins-lib@WAIQ-1884')_

package_pipeline('.')

When the pipeline gets executed by Jenkins, I get this error right after the POD is created by Jenkins:

[Bitbucket] Notifying pull request build result
[Bitbucket] Build result notified
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: container.call() is applicable for argument types: (java.lang.String, org.jenkinsci.plugins.workflow.cps.CpsClosure2) values: [julia, org.jenkinsci.plugins.workflow.cps.CpsClosure2@3754983a]
Possible solutions: wait(), any(), run(), run(), find(), dump()

Jenkins version: 2.235.1

What am I doing wrong?

I think drop the script part, your shared library should already be in scripted mode.

Didn’t help… the same issue persists…

Just made a test in a brand new jenkins instance with the latest k8s plugin version and I have exactly the same error.

Jenkins version: 2.346.1
Kubernetes version: 3651.v908e7db_10d06

I found the issue! Within the vars/ directory, I had another file called container.groovy. And it was the root cause of the issue because sounds like that its name was conflicting with another global library named also as container. So, I renamed it to vars/containers.groovy and it worked.

I wasn’t expecting that it could be the ofensor and that’s why I hide it from the description.

1 Like

Thanks a lot for your feedback. :pray: