How to refer to an object in a shared library?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to refer to an object in a shared library?

ZillaYT
I use this extensibly in my pipelines
https://www.jenkins.io/doc/book/pipeline/shared-libraries/

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()


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a4fee179-0f21-4827-bae4-8f6a457cf2den%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to refer to an object in a shared library?

ZillaYT
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()

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?
On Thursday, September 17, 2020 at 3:22:46 PM UTC-4 [hidden email] wrote:
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()


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/172ca56b-24a7-4e3a-bf37-1aa153793ddan%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to refer to an object in a shared library?

Ven H
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


On Fri, Sep 18, 2020 at 12:56 AM [hidden email] <[hidden email]> wrote:
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()

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?
On Thursday, September 17, 2020 at 3:22:46 PM UTC-4 [hidden email] wrote:
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()


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/172ca56b-24a7-4e3a-bf37-1aa153793ddan%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPp28epi%2B8G0nn5zJfveu0-ayd6U8X87_5MekTWveYSux%3DE91g%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to refer to an object in a shared library?

ZillaYT
Oh, let me try that. Thanks

On Friday, September 18, 2020 at 2:51:47 AM UTC-4 [hidden email] wrote:
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


On Fri, Sep 18, 2020 at 12:56 AM [hidden email] <[hidden email]> wrote:
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()

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?
On Thursday, September 17, 2020 at 3:22:46 PM UTC-4 [hidden email] wrote:
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()


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/172ca56b-24a7-4e3a-bf37-1aa153793ddan%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/50afe979-005a-4efd-b719-b636f81a98dan%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to refer to an object in a shared library?

ZillaYT
Venkatesh,

That was it. Thanks.

Chris

On Friday, September 18, 2020 at 3:52:01 PM UTC-4 [hidden email] wrote:
Oh, let me try that. Thanks

On Friday, September 18, 2020 at 2:51:47 AM UTC-4 [hidden email] wrote:
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


On Fri, Sep 18, 2020 at 12:56 AM [hidden email] <[hidden email]> wrote:
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()

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?
On Thursday, September 17, 2020 at 3:22:46 PM UTC-4 [hidden email] wrote:
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()


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/172ca56b-24a7-4e3a-bf37-1aa153793ddan%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8db848ac-d650-4deb-ad1a-b25b42b1f979n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to refer to an object in a shared library?

Ven H
Glad it worked. No problem.

Regards,
Venkatesh


On Sat, Sep 19, 2020 at 1:49 AM [hidden email] <[hidden email]> wrote:
Venkatesh,

That was it. Thanks.

Chris

On Friday, September 18, 2020 at 3:52:01 PM UTC-4 [hidden email] wrote:
Oh, let me try that. Thanks

On Friday, September 18, 2020 at 2:51:47 AM UTC-4 [hidden email] wrote:
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


On Fri, Sep 18, 2020 at 12:56 AM [hidden email] <[hidden email]> wrote:
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()

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?
On Thursday, September 17, 2020 at 3:22:46 PM UTC-4 [hidden email] wrote:
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()


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/172ca56b-24a7-4e3a-bf37-1aa153793ddan%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8db848ac-d650-4deb-ad1a-b25b42b1f979n%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPp28eq%2BQGdscPCb0EaBP0DQSny0UHJz8Qd04Xo8a0Mn5crkzA%40mail.gmail.com.