How to import folder-level shared libraries in jenkins pipeline
Asked Answered
E

1

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?

Epilogue answered 30/4, 2018 at 15:35 Comment(4)
Your understanding of a folder-level shared library is incorrect. A shared library is (currently) organized in this 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.Inscription
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?Shakiashaking
I hope most of your questions will be answered by this section of documentation.Inscription
Or some of the other parts that show you how to configure and setup the library before using it.Inscription
C
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.

Contralto answered 22/7, 2018 at 11:30 Comment(1)
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).Noellanoelle

© 2022 - 2024 — McMap. All rights reserved.