I have two separate libraries (Library A and Library B), I have defined them on the jenkins configuration so they can be both called from the pipeline.
From Library A I would like to call some functions/methods that are defined in Library B.
My logic tells me that I need to import and probably create an instance of Library B inside Library A before I can have access to any of Library B methods. But I have not been successful. I am no expert in Java, however any guidance is greatly appreciated.
What is a Shared Library in Jenkins? A shared library is a collection of independent Groovy scripts which you pull into your Jenkinsfile at runtime. The best part is, the Library can be stored, like everything else, in a Git repository. This means you can version, tag, and do all the cool stuff you're used to with Git.
The @NonCPS annotation is useful when you have methods which use objects which aren't serializable. Normally, all objects that you create in your pipeline script must be serializable (the reason for this is that Jenkins must be able to serialize the state of the script so that it can be paused and stored on disk).
This depends on where the Libraries are are stored.
If they are under ./vars/ then you do not need to import them, as the Jenkinsfile has already imported all scripts via the @Library('sharedLibs') _
. You would just call it, def a = LibraryB.functionA()
If it is under a traditional ./src/com/something/whatevas, then you would do a more traditional import com.something.whateva.Library
at the top of the Library A
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With