Create resusable jenkins pipeline script

后端 未结 4 770
余生分开走
余生分开走 2021-01-31 09:08

I am considering to use Jenkins pipeline script recently, one question is that I don\'t figure out a smart to way to create internal reusable utils code, imagine, I have a commo

4条回答
  •  执笔经年
    2021-01-31 09:52

    The Shared Libraries (docs) allows you to make your code accessible to all your pipeline scripts. You don't have to build a plugin for that and you don't have to restart Jenkins.

    E.g. this is my library and this a Jenkinsfile that calls this common function.


    EDIT (Feb 2017): The library can be accessed through Jenkins' internal Git server, or deployed through other means (e.g. via Chef) to the workflow-lib/ directory within the jenkins user's home directory. (still possible, but very unhandy).

    The global library can be configured through the following means:

    • an @Library('github.com/...') annotation in the Jenkinsfile pointing to the URL of the shared library repo.
    • configured on the folder level of Jenkins jobs.
    • configured in Jenkins configuration as global library, with the advantage that the code is trusted, i.e., not subject to script security.

    A mix of the first and last method would be a not explicitly loaded shared library that is then requested only using its name in the Jenkinsfile: @Library('mysharedlib').

提交回复
热议问题