Load Jenkins Pipeline Shared Library from same repository

前端 未结 7 2146
北恋
北恋 2021-01-31 07:52

TL;DR Is there a way to import code into the Jenkinsfile from the local repository (other than the load step)?

Why?

I\'ve ex

7条回答
  •  执念已碎
    2021-01-31 08:38

    Is there a way to import code into the Jenkinsfile from the local repository (other than the load step)?

    Is there a way (or workaround) to create a shared library in the same repository as the Jenkinsfile and import this library into the Jenkinsfile?

    Yes. Provided that the "directory structure of a Shared Library repository" is observed according to specification, then it's absolutely feasible and no workaround is required to get it working. Basically, your directory structure would require an adjustment along the following lines:

    +- src                     # Groovy source files
    |   +- org
    |       +- foo
    |           +- Bar.groovy  # for org.foo.Bar class
    +- vars
    |   +- foo.groovy          # for global 'foo' variable
    |   +- foo.txt             # help for 'foo' variable
    +- resources               # resource files (external libraries only)
    |   +- org
    |       +- foo
    |           +- bar.json    # static helper data for org.foo.Bar
    +- someModule
    |   +- ...
    |
    |
    +- Jenkinsfile
    

    This answer is not based on a conjecture. Although it's not documented, I have applied this pattern on multiple projects and training, and it works. You do not need to tinker with your job configuration in anyway than is usual.

提交回复
热议问题