我可以将 Jenkins 配置存储在项目存储库中(如 Travis CI)吗? [英] Can I store Jenkins configuration in the project repo (like Travis CI)?

查看:11
本文介绍了我可以将 Jenkins 配置存储在项目存储库中(如 Travis CI)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何在源代码旁边维护 SCM 中的 Jenkins 作业配置?

How do you maintain the Jenkins job configuration in SCM along side the source code?

随着源代码的发展,作业配置也在发展.能够将作业配置保留在 SCM 中将是理想的,具有以下好处:

As source code evolves, so does the job configuration. It would be ideal to be able to keep the job configuration in SCM, for the following benefits:

  • 易于查看谁的更改历史记录,包括作者和描述
  • 能够通过检查修订来重建旧的分支/标签并构建正常工作
  • 无需滚动 UI 即可找到相应的部分并进行更改

我看到有一个 Jenkins Job Builder 插件.我更喜欢 Travis CI 的解决方案,其中作业配置是在 YAML 文件 (.travis.yml) 中维护.有什么好的建议吗?

I see there is a Jenkins Job Builder plugin. I prefer a solution along the lines of Travis CI, where the job configuration is maintained in a YAML file (.travis.yml). Any good suggestions?

注意:我们的大多数项目都使用 Java &马文.

Note: Most of our projects are using Java & Maven.

推荐答案

2016 年更新: Jenkins 现在提供 Jenkinsfile 正是提供了这一点.这是由核心 Jenkins 开发人员支持并积极开发的.

Update 2016: Jenkins now provides a Jenkinsfile which provides exactly this. This is supported by the core Jenkins developers and actively developed.

好处:

创建一个签入源代码控制的 Jenkinsfile 提供了许多直接的好处:

Creating a Jenkinsfile, which is checked into source control, provides a number of immediate benefits:

  • 管道上的代码审查/迭代
  • 管道的审计跟踪
  • 管道的单一事实来源,可供项目的多个成员查看和编辑.

<小时>

我已经编写了一个插件来做到这一点!

除了我的插件之外,现有的 Jenkins 插件还有一些(有限的)选项:

Other than my plugin, you have some (limited) options with existing Jenkins plugins:

如果您将 Jenkins 配置为简单地运行:

If you configure your Jenkins to simply run:

$ bash run_tests.sh

然后您可以将 run_tests.sh 文件签入到您的 SCM 存储库中,您现在可以跟踪运行测试方式的更改.但是,这不会跟踪任何插件的配置.

You can then check in a run_tests.sh file into your SCM repo and you're now tracking changes for how you run tests. However, this won't track configuration of any plugins.

同样,如果您使用 Maven,Maven 项目插件 只是为你的 repo 运行一个指定的目标.

Similarly, if you're using Maven, the Maven Project Plugin simply runs a specified goal for your repo.

Literate Plugin 确实允许 Jenkins 在您的README.md,但尚未发布.

The Literate Plugin does allow Jenkins to run the commands in your README.md, but it hasn't yet been released.

您可以使用 SCM 同步配置插件将配置更改写入 SCM,因此您至少有一个持久记录.这是全球性的,适用于您的 Jenkins 实例上的所有项目.

You can use the SCM Sync configuration plugin to write configuration changes to SCM, so you at least have a persistent record. This is global, across all projects on your Jenkins instance.

还有 作业配置历史插件,它存储配置历史在文件系统上.

There's also the job config history plugin, which stores config history on the filesystem.

您提到的 Jenkins job builder 项目可以让您检查配置更改到 SCM 和将它们应用于您的 Jenkins 实例.同样,这适用于您的 Jenkins 实例上的所有项目.

The Jenkins job builder project you mentioned lets you check config changes into SCM and have them applied to your Jenkins instance. Again, this is across all projects on your Jenkins instance.

您可以将 Job DSL 插件 与 repo 一起使用groovy 脚本.然后 Jenkins 轮询该 repo,执行 groovy 脚本,创建作业配置.

You can use the Job DSL Plugin with a repo of groovy scripts. Jenkins then polls that repo, executes the groovy scripts, which create job configurations.

Issue 996(现已关闭)讨论了这个问题,它也已经在邮件列表中讨论:'跟踪 Hudson 的配置更改',和 'save hudson config in svn'.

Issue 996 (now closed) discusses this, and it has also been discussed on the mailing list: 'Keeping track of Hudson's configuration changes', and 'save hudson config in svn'.

这篇关于我可以将 Jenkins 配置存储在项目存储库中(如 Travis CI)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆