Pipeline DSL using a shared lib which is a java class

20 views
Skip to first unread message

Charles Moulliard

unread,
Jan 6, 2021, 12:23:12 PM1/6/21
to Jenkins Users
Hi,

Can we define a pipeline DSL script importing a shared lib which is a java class ?

Script
@org.jenkinsci.plugins.workflow.libs.Library('mytools')

import org.mytools.Messaging // The Java class imported as shared lib 
Messaging m = new Messaging();

The java class has been defined under the folder `src/main/org/mytools/Messaging.java` within the git project cloned as shared lib

Cheers

Charles

Ivan Fernandez Calvo

unread,
Jan 7, 2021, 12:02:47 PM1/7/21
to Jenkins Users

Charles Moulliard

unread,
Jan 8, 2021, 2:04:09 AM1/8/21
to jenkins...@googlegroups.com
Many thanks Ivan for the example which is a Groovy class and not a java class. According to the documentation, I don't think that we can use some java classes directly from a shared lib project excepted if thy have been compiled, packaged as jar under a maven repository and that you import it using "@Grab" - https://www.jenkins.io/doc/book/pipeline/shared-libraries/#using-third-party-libraries



--
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/1216e835-5752-482f-b887-565bc4cc7194n%40googlegroups.com.

Ivan Fernandez Calvo

unread,
Jan 8, 2021, 6:48:32 AM1/8/21
to Jenkins Users
If a class is in the classpath, you can use it on a Pipeline Step or in a groovy class (the example), then you can use that step(or groovy class) in your pipeline. So instead of trying to load a jar file in runtime you can put the jar in the classpath of your Jenkins instance and wrap the class ina step (or groovy class)
Reply all
Reply to author
Forward
0 new messages