在作业之间共享配置

Sharing configuration between jobs

我有几个 Jenkins 作业。它们看起来非常相似,仅在细节上有所不同。最初它们是通过复制第一份工作创建的。 如果其中一个作业配置发生变化,则必须将其应用于所有其他作业配置。这使得 Jenkins 维护更复杂、时间更长且更容易出错。

我想做的是至少提取作业配置的一些通用部分并将其保存在一个地方,这样我就不必将每个配置更改分别应用于所有作业。是否可能,如果可能,如何实现?

我不想创建新项目或更改作业的结构方式(上游-下游依赖性),因为所有这些作业都是遗留的。

提前致谢!

有几个插件可以帮助解决这个问题。 Inheritance 想到插件

你也可以看看 Template Project plugin.

使用此插件,您可以使用模板作业中的构建器、发布器和 SCM 设置。

我们公司正在使用这个插件,效果很好:)

我觉得Jenkins DSL Plugin也可以用来解决这个问题。

根据其总结:

Jenkins is a wonderful system for managing builds, and people love using its UI to configure jobs. Unfortunately, as the number of jobs grows, maintaining them becomes tedious, and the paradigm of using a UI falls apart. Additionally, the common pattern in this situation is to copy jobs to create new ones, these "children" have a habit of diverging from their original "template" and consequently it becomes difficult to maintain consistency between these jobs.

它可以使用 Groovy 领域特定语言以编程方式创建作业。