![](/img/trans.png)
[英]How can I create a shared library in Jenkins with both arguments and a body?
[英][Jenkins]How can I create a shared library remotely?
我的常規腳本都在git倉庫中,使用jenkins checkout SCM。 一些常見的功能位於groovy腳本之一中,我想將此groovy設為共享庫,而無需打開jenkins並在Jenkins Manage表中添加共享庫。
我可以使用rest API或其他方法添加新庫嗎?
如果您的存儲庫與共享庫結構(如vars dir)保持一致,則可以從jenkinsfile動態加載共享庫。
您需要使用library
命令並提供所有相關參數。
對於所有參數選項,您可以使用代碼段幫助選項。
是的,您可以從源代碼管理動態加載庫]: https : //jenkins.io/doc/book/pipeline/shared-libraries/#dynamic-retrieval 。 這看起來像
library(identifier: 'pipeline-helper@master', retriever: modernSCM(
[$class: 'GitSCMSource',
remote: 'https://github.com/papanito/jenkins-pipeline-helper.git',
credentialsId: 'github.user'
]))
如果您在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.