How to Import a java jar on jenkins to be used by Job DSL - Groovy Script ?

530 views
Skip to first unread message

Charles Moulliard

unread,
Dec 14, 2020, 10:55:47 AM12/14/20
to Jenkins Users
Hi,

How can we Import a java jar on jenkins in order to allow a Groovy Script part of a Job DSL to use java classes packaged within the jar file ?

Example of groovy script using the Java class Hello and method "message" 

package groovy
import dev.snowdrop.jenkins.Hello;
println new Hello().message();

Cheers 

Charles

Nick Stolwijk

unread,
Dec 14, 2020, 11:12:04 AM12/14/20
to jenkins...@googlegroups.com
Hi Charles,

I think you can do this using the third party library @Grab [1]. I have taken a look in the documentation of Grape [2] and I see they use a custom Maven repository to load the libraries.


Hth,

Nick Stolwijk

~~~ Try to leave this world a little better than you found it and, when your turn comes to die, you can die happy in feeling that at any rate you have not wasted your time but have done your best ~~~

Lord Baden-Powell


--
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/d28daa31-1da7-423c-ab7c-f14820f985ecn%40googlegroups.com.

Yeikel

unread,
Dec 14, 2020, 11:13:17 AM12/14/20
to jenkins...@googlegroups.com

--

Nick Stolwijk

unread,
Dec 14, 2020, 11:14:44 AM12/14/20
to jenkins...@googlegroups.com
Sorry, missed the part about JobDSL. I found a plugin which makes that possible: https://github.com/AOEpeople/gradle-jenkins-job-dsl-plugin

With regards,

Nick Stolwijk

~~~ Try to leave this world a little better than you found it and, when your turn comes to die, you can die happy in feeling that at any rate you have not wasted your time but have done your best ~~~

Lord Baden-Powell

Yeikel

unread,
Dec 14, 2020, 11:16:21 AM12/14/20
to jenkins...@googlegroups.com
As per the documentation @grap is an option but it is not recommended.

You should either create a shared library or call `sh java jar...` and it all depends on what you need.

Charles Moulliard

unread,
Dec 14, 2020, 11:28:14 AM12/14/20
to Jenkins Users
The approach you propose is only supported if you create Pipeline Jobs.

Charles Moulliard

unread,
Dec 14, 2020, 11:28:30 AM12/14/20
to Jenkins Users
Same remark as before. The approach you propose is only supported if you create Pipeline Jobs.
Reply all
Reply to author
Forward
0 new messages