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)

El viernes, 8 de enero de 2021 a las 8:04:09 UTC+1, [email protected] 
escribió:

> 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
>
>
>
> On Thu, Jan 7, 2021 at 6:02 PM Ivan Fernandez Calvo <[email protected]> 
> wrote:
>
>> you can use directly a class from the Shared library
>>
>> This is an example in our shared library (
>> https://github.com/elastic/apm-pipeline-library)
>>
>> https://github.com/elastic/apm-pipeline-library/blob/master/src/co/elastic/matrix/DefaultParallelTaskGenerator.groovy
>>
>> and a pipeline that uses that class
>>
>> https://github.com/elastic/apm-integration-testing/blob/master/.ci/integrationTestDownstream.groovy#L89
>>
>> El miércoles, 6 de enero de 2021 a las 18:23:12 UTC+1, [email protected] 
>> escribió:
>>
>>> 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
>>>
>> -- 
>> 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 [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jenkinsci-users/1216e835-5752-482f-b887-565bc4cc7194n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/jenkinsci-users/1216e835-5752-482f-b887-565bc4cc7194n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/ea644d78-cd3d-4ebc-aa68-6dd1f379ae21n%40googlegroups.com.

Reply via email to