9

First my understanding of folder-level shared libraries: It's a groovy script I can place anywhere in the repository where I want it to use (i.e. where my Jenkinsfile will be).

If this is wrong please let me know.

My question: How can I include this library. For global libraries I can use @Library($libraryName) to import libraries I registered with a name as global library. But for folder-level libraries there is no name specified. How do I import them? Do I really have to specify the git repo like demonstrated in this answer?

Yannic Bürgmann
  • 6,301
  • 5
  • 43
  • 77
  • 2
    Your understanding of a folder-level shared library is incorrect. A shared library is (currently) organized in [this directory structure](https://jenkins.io/doc/book/pipeline/shared-libraries/#directory-structure) and can be loaded using `@Library` or the other supporting APIs (like `library` step). Maybe you are looking for the `load` step to use scripts in the same repository? It depends on what you are trying to accomplish. – mkobit Apr 30 '18 at 19:23
  • 1
    Thank you for your answer. Right now I just try to understand what a folder-level-shared library is. From the documentation it's not getting clear to me. Where do I register this library? Where/When do I use it? How do I use it? – Yannic Bürgmann May 02 '18 at 07:16
  • I hope most of your questions will be answered by [this section of documentation](https://jenkins.io/doc/book/pipeline/shared-libraries/#folder-level-shared-libraries). – mkobit May 02 '18 at 14:04
  • Or some of the other parts that show you how to configure and setup the library before using it. – mkobit May 02 '18 at 20:34

1 Answers1

7

Folder-level shared libraries work similar to global shared libraries.

They also need a dedicated repository featuring the known layout (vars, src folders). And you need to load them using @Library(<name>) _ if you choose not to load implicitly.

Differences are:

  • You define the library to use in the settings of a Jenkins folder
  • They are not trusted (as written in the link posted in the comments)

Just open the settings of a Jenkins folder and you'll find the options.

mirekphd
  • 4,799
  • 3
  • 38
  • 59
Joerg S
  • 4,730
  • 3
  • 24
  • 43
  • For those not familiar with folders, they can be created in Jenkins by going to "New Item" and selecting "Folder". I guess it's kind of like a View, but allows for an additional level of granularity (including shared libraries). – trebor Aug 12 '23 at 01:27