如何获取子模块以触发Jenkins构建 [英] how to get submodules to trigger a Jenkins build
问题描述
我有一个不是独立应用程序的子模块A.它需要主要的应用程序才能运行.我想为A创建一个CI构建,以便每当将提交推送到A时,它就会触发带有主要项目代码的构建.
I have a submodule A that is not a standalone application. It requires the main application for it to work. I would like to create a CI build for A so that whenever a commit is pushed to A it triggers a build with the main project code.
我如何在詹金斯做到这一点?
How do I do that in Jenkins?
我需要做什么:
- 对A的提交会触发构建.
- 内部版本会克隆Main项目代码,并在A的最新提交(不是Main Project知道的提交)时拉取A的最新代码.
我如何使用Jenkins和GIT来做到这一点?
How would I do that using Jenkins and GIT?
请注意,我有该项目的多个子模块.子模块A触发了一个构建,该构建从A中获取最新更改,并从主代码中获取最新更改,并从其他子模块中获取更新.
Note I have multiple submodules for the project. Submodule A triggers a build that pulls the latest changes from A and also the latest of main code and pulls updates from the other submodules.
推荐答案
这可以在没有git钩子的情况下完成.在此示例中,我们有3个存储库:
This can be done without git hooks. In this example we have 3 repos:
- 父母
- 只有子模块的空仓库
- parent
- Empty repo that just has submodules
- 一个子子模块存储库
- 另一个子子模块存储库
与子模块一起克隆时,它看起来像:
When cloned with sub-modules it looks like:
parent\
child-a\*
child-b\*
在Jenkins中创建一个名为dummy-child-a
的自由式项目.
In Jenkins create a freestyle project called dummy-child-a
.
- 在
Source Code Management
下,将Repository URL
设置为child-a
- 在
Build Triggers
下,选择Poll SCM
并设置所需的时间间隔 - 在
Build
下,单击Add build step
- 根据您的操作系统选择
Execute Windows batch command
或Execute shell
- 在脚本框中执行类似
echo hello
的操作(这是虚拟部分)
- Under
Source Code Management
setup theRepository URL
forchild-a
- Under
Build Triggers
you choosePoll SCM
and set your desired interval - Under
Build
clickAdd build step
- Choose
Execute Windows batch command
orExecute shell
depending on your OS - In the script box do something like
echo hello
(this is the dummy part)
为
child-b
在Jenkins中创建一个名为
parent
的自由式项目.这是我们实际要做的地方In Jenkins create a freestyle project called
parent
. This is where we will actually do the building- 在
Source Code Management
下,将Repository URL
设置为parent
- 单击
Additional Behaviours
下的add
,然后选择Advanced sub-modules behaviours
- 检查:
-
Recursively update submodules
-
Update tracking submodules to tip of branch
-
Use credentials from default remote of parent repository
- Under
Source Code Management
setup theRepository URL
forparent
- Click
add
underAdditional Behaviours
and chooseAdvanced sub-modules behaviours
- Check:
Recursively update submodules
Update tracking submodules to tip of branch
Use credentials from default remote of parent repository
- 在
Projects to watch
字段中,以逗号分隔的形式填充所有要观看的项目:dummy-child-a, dummy-child-b
- 如果
parent
没有可更改的源代码,则您无需Poll SCM
进行此詹金斯工作 - 检查
Trigger even if the build fails
- In the
Projects to watch
field, fill all projects to watch with comma separation:dummy-child-a, dummy-child-b
- If
parent
doesn't have source code that will change, You don't need toPoll SCM
on this Jenkins job - Check
Trigger even if the build fails
您已经完成.对子级a或子级b的任何更改都会触发父级的重建.此方法假定父级中子模块的数量很少更改.如果要添加另一个子模块,则需要创建另一个
dummy
项目,然后更新parent
Jenkins版本的projects to watch
.And you're done. Any changes to either child-a or child-b will trigger a rebuild of parent. This method assumes that the number of submodules in parent changes infrequently. If you were to add another submodule you would need to make another
dummy
project, and then update theprojects to watch
of theparent
Jenkins build.这篇关于如何获取子模块以触发Jenkins构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Choose
- 根据您的操作系统选择