<p>It looks like Groovy can't find your class at the path specified.</p>

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

<pre><code>src/org/common/CommonFuncs.groovy
</code></pre>

CC BY-SA 4.0
2023-02-20T03:10:35.360Z
I was creating a filename with lowercase style, but remembering what u mentioned, helped me a lot, specially the words highlighted in the jenkins documentation :
`The basename of each .groovy file should be a Groovy (~ Java) identifier, conventionally camelCased.` , reference : https://www.jenkins.io/doc/book/pipeline/shared-libraries/#directory-structure
Manuel Lazo
CC BY-SA 4.0
2020-05-14T07:08:32.830Z
2020-05-14T07:08:32.830Z
Guido Vaccarella
<p>Here is the folder structure in my shared library repo:</p>

<pre><code>$ tree src vars
src
├── org
    └── common.groovy

vars
├── testSrc.groovy
</code></pre>

<p>src has:</p>

<pre><code>$ cat src/org/common.groovy
package org.common

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

    def sayHello(str) {
        echo "Hello ${str}"
    }
}
</code></pre>

<p>and vars:</p>

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

<p>pipeline script in Jenkins has:</p>

<pre><code>@Library('jenkins-library') _
pipeline {
    agent { label 'my_servers' }

    stages {
        stage('test') {
            steps {
                testSrc()
            }
        }
    }
}
</code></pre>

<p>When I run job, I get below error:</p>

<pre><code>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()
                 ^
</code></pre>

<p>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.</p>

CC BY-SA 4.0
2020-05-13T13:42:02.013Z
is it possible to have the class in src/ and use it in vars/?
rodee
CC BY-SA 4.0
2020-05-13T16:36:15.287Z
Try renaming common.groovy in CommonFuncs.groovy and moving it to src/org/common/.
Guido Vaccarella
CC BY-SA 4.0
2020-05-13T17:06:15.893Z
That worked, renamed the groovy file to match class name. thank you.
rodee
CC BY-SA 4.0
2020-05-13T18:48:27.847Z
@GuidoVaccarella, can you add it as answer?
rodee
<jenkins-pipeline><groovy>
Unable to use the class defined in src in vars of jenkins shared library
rodee
# Unable to use the class defined in src in vars of jenkins shared library

(Asked by: username_0 on 2020-05-12)

Here is the folder structure in my shared library repo:
$ tree src vars
src
├── org
    └── common.groovy

vars
├── 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 {
                testSrc()
            }
        }
    }
}

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.

**Tags:** jenkins-pipeline, groovy

> **Comments:**
> **username_0**: is it possible to have the class in src/ and use it in vars/?  
> **username_1**: Try renaming common.groovy in CommonFuncs.groovy and moving it to src/org/common/.  
> **username_0**: That worked, renamed the groovy file to match class name. thank you.  
> **username_0**: @GuidoVaccarella, can you add it as answer?  

---

## 1 answers

### Answer by username_1 on 2020-05-14. Score: 3 | Accepted answer

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:
src/org/common/CommonFuncs.groovy

> **Comments:**
> **username_2**: I was creating a filename with lowercase style, but remembering what u mentioned, helped me a lot, specially the words highlighted in the jenkins documentation : `The basename of each .groovy file should be a Groovy (~ Java) identifier, conventionally camelCased.` , reference : https://www.jenkins.io/doc/book/pipeline/shared-libraries/#directory-structure  

---

