How to call functions in one Jenkins Shared Library from another

孤人 提交于 2019-12-12 09:45:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!