jenkins - 组合多个jenkins共享库
问题描述
是否可以组合多个共享的 Jenkins 库?
例如,我有一个公共共享库:my-shared-library(带有 maven 项目的 git 存储库)在包含一些作业的 jenkins 文件夹中定义。在该文件夹中运行的每个作业都可以使用 Jenkinsfile 中的共享库:
@Library("my-shared-library") _
import com.pipelines.Pipeline
new Pipeline().build()
现在我想创建另一个共享库:my-specialized-shared-library,其中包含一些专用管道(在另一个 git 存储库中也作为 maven 项目)。my-specialized-shared-library中的管道(groovy 类、脚本等)应该能够从以下位置使用/导入类、管道等: my-shared-library是可能的,如果可以,推荐的方法是什么?
解决方案
在管理 Jenkins > 配置系统中,我从不同的 URL 定义了 2 个不同的全局管道库。
- 全球图书馆-1
- 全球图书馆-2
.jenkins 文件:
@Library('GlobalLibrary-1@some_branch') l1 //you can write here _ (underscore) or any other string.
@Library('GlobalLibrary-2@any_branch') l2
import com.lib1.Class1; // import from GlobalLibrary-1 (Jenkins automatically finds com.lib.Class1 inside GlobalLibrary-1)
import com.prodcode.Class2; // import from GlobalLibrary-2 (Jenkins automatically finds com.prodcode.Class2 inside GlobalLibrary-2)
node {
new Class1();
new Class2();
}
我什至可以在Class2.groovy中使用导入来从 GlobalLibrary -1获取类。
推荐阅读
- php - 如何隐藏选择选项值并用新值替换 2 个选项?
- git - 如何从存储库中已有的特定 TAG 更改文件?
- java - 无法解决类异常:com.blazemeter.jmeter.RandomCSVDataSetConfig
- azure - DATABRICKS 数据库文件系统
- jquery - 有没有办法使用汇总在 ES6 和 UMD 中编写 jQuery 插件
- python - Anaconda:安装 mgwr 时出现 UnsatisfiableError
- angularjs - 如何使用 angularJS ui-mask 强制 2 或 3 个字符或数字
- c# - xslt 到多个输出
- angular - 通过在组件的 css 中导入加载 css 和脚本与在索引中链接它
- javascript - 如果存在超过一定数量,则隐藏列表项