How to refer to an object in a shared library?

87 views
Skip to first unread message

zil...@gmail.com

unread,
Sep 17, 2020, 3:22:46 PM9/17/20
to Jenkins Users
I use this extensibly in my pipelines

For example, I can have the following files
/path/src/com/company/deployment/script1.groovy
/path/src/com/company/deployment/script2.groovy

Now I want both scripts to refer to a common object in
/path/src/com/company/deployment/common.groovy

For example

common.groovy
package com.company.deployment.common
class MyClass {
}

script1.groovy
package com.company.deployment
import com.company.deployment.common
MyClass mc = new MyClass()

scrpt2.groovy
package com.company.deployment
import com.company.deployment.common
MyClass mc = new MyClass()


zil...@gmail.com

unread,
Sep 17, 2020, 3:26:31 PM9/17/20
to Jenkins Users
But I get the following with I try to run either script1 or script2
unable to resolve class MyClass

What else do I need to do?

Ven H

unread,
Sep 18, 2020, 2:51:47 AM9/18/20
to jenkins...@googlegroups.com
Hi,

Even if you are importing the namespace, use the full name for the class and try. For example,

com.company.deployment.common.MyClass obj = new com.company.deployment.common.MyClass()

Regards,
Venkatesh


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/172ca56b-24a7-4e3a-bf37-1aa153793ddan%40googlegroups.com.

zil...@gmail.com

unread,
Sep 18, 2020, 3:52:01 PM9/18/20
to Jenkins Users
Oh, let me try that. Thanks

zil...@gmail.com

unread,
Sep 18, 2020, 4:19:24 PM9/18/20
to Jenkins Users
Venkatesh,

That was it. Thanks.

Chris

Ven H

unread,
Sep 21, 2020, 12:02:51 PM9/21/20
to jenkins...@googlegroups.com
Glad it worked. No problem.

Regards,
Venkatesh


Reply all
Reply to author
Forward
0 new messages