简体   繁体   English

[Jenkins]如何远程创建共享库?

[英][Jenkins]How can I create a shared library remotely?

My groovy scripts are all in git repository, using jenkins checkout SCM. 我的常规脚本都在git仓库中,使用jenkins checkout SCM。 Some common functions are in one of the groovy scripts, I want to make this groovy a shared-library without opening jenkins and add shared library in Jenkins Manage table. 一些常见的功能位于groovy脚本之一中,我想将此groovy设为共享库,而无需打开jenkins并在Jenkins Manage表中添加共享库。

Can I add a new library using rest API or other methods? 我可以使用rest API或其他方法添加新库吗?

if your repository is align with shared library structure, like vars dir, than you can load the shared library dynamically from the jenkinsfile. 如果您的存储库与共享库结构(如vars dir)保持一致,则可以从jenkinsfile动态加载共享库。

You need to use the library command and provide all relevant parameters. 您需要使用library命令并提供所有相关参数。

For all parameters options you can use the snippet help option. 对于所有参数选项,您可以使用代码段帮助选项。

Yes you can load a library dynamically] from source control: https://jenkins.io/doc/book/pipeline/shared-libraries/#dynamic-retrieval . 是的,您可以从源代码管理动态加载库]: https : //jenkins.io/doc/book/pipeline/shared-libraries/#dynamic-retrieval This would look something like 这看起来像

library(identifier: 'pipeline-helper@master', retriever: modernSCM(
  [$class: 'GitSCMSource',
       remote: 'https://github.com/papanito/jenkins-pipeline-helper.git',
       credentialsId: 'github.user'
]))

If you have a static helper class under src/com/example/MyClass you would do something like this: 如果您在src/com/example/MyClass下有一个静态帮助器类,则可以执行以下操作:

def MyClass = library(identifier: 'pipeline-helper@master', retriever: modernSCM(
  [$class: 'GitSCMSource',
       remote: 'https://github.com/papanito/jenkins-pipeline-helper.git',
       credentialsId: 'github.user'
])).com.example.MyClass


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM