Here is the folder structure in my shared library repo:

$ tree src vars
├── org
    └── common.groovy

├── testSrc.groovy

src has:

$ cat src/org/common.groovy
package org.common

class CommonFuncs {
    def sayHi() {
        echo "Hi from CommonFuncs!"

    def sayHello(str) {
        echo "Hello ${str}"

and vars:

$ cat vars/testSrc.groovy
def call() {
    def tst = new org.common.CommonFuncs()
    return tst.sayHi()

pipeline script in Jenkins has:

@Library('jenkins-library') _
pipeline {
    agent { label 'my_servers' }

    stages {
        stage('test') {
            steps {

When I run job, I get below error:

org.jenkinsci.plugins.workflow.cps.CpsCompilationErrorsException: startup failed:
/var/jenkins_home/jobs/Test/jobs/mave/jobs/test_src/builds/8/libs/jenkins-library/vars/testSrc.groovy: 2: unable to resolve class org.common.CommonFuncs 
 @ line 2, column 15.
       def tst = new org.common.CommonFuncs()

What is wrong in here? I am new to groovy, and this is my first attempt to create a class in shared library src/, any help is appreciated.

  • is it possible to have the class in src/ and use it in vars/?
    – rodee
    May 13 '20 at 13:42
  • Try renaming common.groovy in CommonFuncs.groovy and moving it to src/org/common/. May 13 '20 at 16:36
  • That worked, renamed the groovy file to match class name. thank you.
    – rodee
    May 13 '20 at 17:06
  • @GuidoVaccarella, can you add it as answer?
    – rodee
    May 13 '20 at 18:48

It looks like Groovy can't find your class at the path specified.

Try renaming the file common.groovy to match the class name and move it to the common folder:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.