Shared Library Feature

19 views
Skip to first unread message

Dashmeet Anand

unread,
Apr 11, 2024, 4:51:24 PM4/11/24
to jenkins-job-builder
Is there any feature available similar to shared library for Jenkins?
With shared library we can use groovy code using import statements.

Thanh Ha

unread,
Apr 11, 2024, 9:21:08 PM4/11/24
to Dashmeet Anand, jenkins-job-builder
Hi Dashmeet,

We've achieved this by loading our library jjb repo as a submodule in git. For example we maintain a jjb library repo called global-jjb (

Here's a project which uses this library by loading it as a git submodule.


If you're using git this might be an option for you.

Hope this helps,
Thanh


On Thu, Apr 11, 2024 at 16:51 Dashmeet Anand <dashi...@gmail.com> wrote:
Is there any feature available similar to shared library for Jenkins?
With shared library we can use groovy code using import statements.

--
You received this message because you are subscribed to the Google Groups "jenkins-job-builder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins-job-bui...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkins-job-builder/ad848022-c270-4910-923f-2465b3484f0an%40googlegroups.com.

Dashmeet Anand

unread,
Apr 12, 2024, 1:42:30 PM4/12/24
to jenkins-job-builder
Thanks for the reply Thanh!

If I'm understanding correctly, the way we can use shared library feature is through job templates.
Global JJB provides some reusable job templates which you are using in releng-builder.

Would you be able to direct me to one example of how you are using job template from global jjb in your package.

Please correct me if my understanding is not correct. 

Thanks,
Dashmeet

Thanh Ha

unread,
Apr 12, 2024, 1:56:47 PM4/12/24
to Dashmeet Anand, jenkins-job-builder
That's correct. Pretty much all of the jobs in releng-builder are pulling templates from global-jjb. Here's one of the yamls. It should look pretty normal.


For example the {project-name}-rtd-jobs in that file is a job template in global-jjb here:


The reason this works is because using git submodules to pull global-jjb, it just appears as a sub-folder inside releng-builder so you can refer to job-templates as usual.

Git submodules does add some overhead though because to use new versions of job templates you have to update the git submodule but it can also be a good thing because users of your library can upgrade at their own pace.

Hope this helps,
Thanh

Reply all
Reply to author
Forward
0 new messages