问题
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.
回答1:
In Jenkinsfile:
@Library(['libA', 'libB']) _
and you can call between them:
import org.myorg.PruebaA / import org.myorg.PruebaB
回答2:
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
来源:https://stackoverflow.com/questions/48308804/how-to-call-functions-in-one-jenkins-shared-library-from-another