我可以将 Jenkins 配置存储在项目仓库中吗(比如 Travis CI)?
Can I store Jenkins configuration in the project repo (like Travis CI)?
您如何维护 SCM 中的 Jenkins 作业配置以及源代码?
随着源代码的发展,作业配置也在发展。如果能够在 SCM 中保留作业配置,那将是理想的,因为它有以下好处:
- 轻松查看更改历史记录,包括作者和描述
- 能够通过检查修订和构建正常工作来重建旧 branch/tag
- 无需滚动浏览 UI 即可找到合适的部分并进行更改
我看到有一个 Jenkins Job Builder plugin. I prefer a solution along the lines of Travis CI,作业配置保存在 YAML 文件 (.travis.yml) 中。有什么好的建议吗?
注意:我们的大部分项目都在使用 Java & Maven。
2016 年更新: Jenkins 现在提供了一个 Jenkinsfile,它正好提供了这一点。这是由核心 Jenkins 开发人员支持并积极开发的。
好处:
Creating a Jenkinsfile, which is checked into source control, provides a number of immediate benefits:
- Code review/iteration on the Pipeline
- Audit trail for the Pipeline
- Single source of truth for the Pipeline, which can be viewed and edited by multiple members of the project.
我 written a plugin 做到了!
除了我的插件之外,现有的 Jenkins 插件还有一些(有限的)选项:
使用单个测试脚本
如果您将 Jenkins 配置为 运行:
$ bash run_tests.sh
然后您可以将 run_tests.sh
文件签入您的 SCM 存储库,您现在可以跟踪 运行 测试方式的更改。但是,这不会跟踪任何插件的配置。
同样,如果您使用的是 Maven,Maven Project Plugin 只是 运行 为您的存储库指定的目标。
Literate Plugin 确实允许 Jenkins 运行 您 README.md 中的命令,但尚未发布。
跟踪对 Jenkins 配置的更改
您可以使用SCM Sync configuration plugin将配置更改写入SCM,这样您至少有一个持久记录。这是全局的,跨您 Jenkins 实例上的所有项目。
还有 job config history plugin,它在文件系统上存储配置历史记录。
从 SCM 编写 Jenkins 配置
您提到的 Jenkins job builder 项目允许您将配置更改检查到 SCM 并将它们应用到您的 Jenkins 实例。同样,这涉及您 Jenkins 实例上的所有项目。
从另一个作业编写 Jenkins 配置
您可以将 Job DSL Plugin 与 groovy 脚本的存储库一起使用。 Jenkins 然后轮询该 repo,执行 groovy 脚本,创建作业配置。
讨论
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'.
您可以使用 workflow plugin 完成这一切,还有更多。工作流是使用jenkins最先进的技术之一,它有很强的支持。
它基于 groovy DSL,允许您将整个配置保留在您选择的 SCM 中(例如 GIT、SVN...)。
您如何维护 SCM 中的 Jenkins 作业配置以及源代码?
随着源代码的发展,作业配置也在发展。如果能够在 SCM 中保留作业配置,那将是理想的,因为它有以下好处:
- 轻松查看更改历史记录,包括作者和描述
- 能够通过检查修订和构建正常工作来重建旧 branch/tag
- 无需滚动浏览 UI 即可找到合适的部分并进行更改
我看到有一个 Jenkins Job Builder plugin. I prefer a solution along the lines of Travis CI,作业配置保存在 YAML 文件 (.travis.yml) 中。有什么好的建议吗?
注意:我们的大部分项目都在使用 Java & Maven。
2016 年更新: Jenkins 现在提供了一个 Jenkinsfile,它正好提供了这一点。这是由核心 Jenkins 开发人员支持并积极开发的。
好处:
Creating a Jenkinsfile, which is checked into source control, provides a number of immediate benefits:
- Code review/iteration on the Pipeline
- Audit trail for the Pipeline
- Single source of truth for the Pipeline, which can be viewed and edited by multiple members of the project.
我 written a plugin 做到了!
除了我的插件之外,现有的 Jenkins 插件还有一些(有限的)选项:
使用单个测试脚本
如果您将 Jenkins 配置为 运行:
$ bash run_tests.sh
然后您可以将 run_tests.sh
文件签入您的 SCM 存储库,您现在可以跟踪 运行 测试方式的更改。但是,这不会跟踪任何插件的配置。
同样,如果您使用的是 Maven,Maven Project Plugin 只是 运行 为您的存储库指定的目标。
Literate Plugin 确实允许 Jenkins 运行 您 README.md 中的命令,但尚未发布。
跟踪对 Jenkins 配置的更改
您可以使用SCM Sync configuration plugin将配置更改写入SCM,这样您至少有一个持久记录。这是全局的,跨您 Jenkins 实例上的所有项目。
还有 job config history plugin,它在文件系统上存储配置历史记录。
从 SCM 编写 Jenkins 配置
您提到的 Jenkins job builder 项目允许您将配置更改检查到 SCM 并将它们应用到您的 Jenkins 实例。同样,这涉及您 Jenkins 实例上的所有项目。
从另一个作业编写 Jenkins 配置
您可以将 Job DSL Plugin 与 groovy 脚本的存储库一起使用。 Jenkins 然后轮询该 repo,执行 groovy 脚本,创建作业配置。
讨论
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'.
您可以使用 workflow plugin 完成这一切,还有更多。工作流是使用jenkins最先进的技术之一,它有很强的支持。
它基于 groovy DSL,允许您将整个配置保留在您选择的 SCM 中(例如 GIT、SVN...)。