我有一个子模块 A,它不是独立的应用程序。它需要主应用程序才能工作。我想为 A 创建一个 CI 构建,以便每当将提交推送到 A 时,它都会触发使用主项目代码的构建。
我该如何在詹金斯中做到这一点?
我需要做什么:
- 对 A 的提交会触发构建。
- 该构建克隆主项目代码,并在 A 的最新提交(不是主项目知道的提交)处提取 A 的最新代码。
我该如何使用 Jenkins 和 GIT 来做到这一点?
注意我的项目有多个子模块。子模块 A 触发构建,从 A 中提取最新的更改以及最新的主代码,并从其他子模块中提取更新。
这可以在没有 git hooks 的情况下完成。在此示例中,我们有 3 个存储库:
- parent
- child-a
- child-b
当使用子模块克隆时,它看起来像:
parent\
child-a\*
child-b\*
在 Jenkins 中创建一个名为的自由式项目dummy-child-a
.
- Under
Source Code Management
设置Repository URL
for child-a
- Under
Build Triggers
你选Poll SCM
并设置您想要的间隔
- Under
Build
click Add build step
- Choose
Execute Windows batch command
or Execute shell
取决于您的操作系统
- 在脚本框中执行类似的操作
echo hello
(这是虚拟部分)
重复这些步骤child-b
在 Jenkins 中创建一个名为的自由式项目parent
。这是我们实际建造的地方
- Under
Source Code Management
设置Repository URL
for parent
- Click
add
under Additional Behaviours
and choose Advanced sub-modules behaviours
- Check:
Recursively update submodules
Update tracking submodules to tip of branch
Use credentials from default remote of parent repository
- Under
Build Triggers
check Build after other projects are built
- In the
Projects to watch
字段,填写所有要观看的项目,并用逗号分隔:dummy-child-a, dummy-child-b
- If
parent
没有会改变的源代码,你不需要Poll SCM
在这个詹金斯工作上
- Check
Trigger even if the build fails
你就完成了。对 child-a 或 child-b 的任何更改都会触发父级的重建。该方法假设父模块中的子模块数量不经常变化。如果您要添加另一个子模块,您将需要制作另一个dummy
项目,然后更新projects to watch
of the parent
詹金斯构建。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)