[英]How to listen to submodule changes without cloning in Jenkins
Jenkins is on a detached head. 詹金斯是一个独立的头。 Whenever a submodule gets updated, I need to trigger a build.
每当子模块更新时,我都需要触发一个构建。 However, only the main project gets cloned.
但是,只有主项目被克隆。
Two questions 两个问题
Basically, I want to give each submodule its own CI environment for testing, but each submodule is not a standalone application; 基本上,我想给每个子模块提供自己的CI环境进行测试,但每个子模块都不是一个独立的应用程序; they depend on the main project.
他们依赖于主要项目。 So when a submodule gets updated, we need the main project updated with the latest code from that submodule without having the submodule cloned, the code from the submodule must be pulled.
因此,当子模块更新时,我们需要使用该子模块中的最新代码更新主项目而不必克隆子模块,必须拉出子模块中的代码。 I don't want to set the polling on the main project.
我不想在主项目上设置轮询。 Jenkins should be checking the submodule each time to check if there is a new commit
Jenkins应该每次检查子模块以检查是否有新的提交
I would recommend one Jenkins job monitoring the parent repo. 我会推荐一个监控父回购的Jenkins工作。
By default, it doesn't clone the submodules if you don't enable Job Configuration -> Section Source Code Management, Git -> Advanced Button (under Branches to build) -> Recursively update submodules
. 默认情况下,如果您不启用
Job Configuration -> Section Source Code Management, Git -> Advanced Button (under Branches to build) -> Recursively update submodules
,它不会克隆子Job Configuration -> Section Source Code Management, Git -> Advanced Button (under Branches to build) -> Recursively update submodules
。
It will just monitor a clone of the parent repo, to fetch the latest commits at regular interval, simply by enabling Poll SCM, not by setting specifying a schedule: see " Automatically triggering a Jenkins build on Git commit ". 它只会监视父repo的克隆,定期获取最新的提交,只需启用Poll SCM,而不是通过设置指定时间表:参见“ 自动触发Jenkins构建Git提交 ”。
If a submodule is updated, that means the parent repo will change as well. 如果子模块已更新,则表示父库将也会更改。
When a submodule changes, a new parent repo SHA1 will be created and pushed as well, recording a gitlink (a special entry in the index ). 当子模块更改时,将创建并推送新的父repo SHA1,记录gitlink ( 索引中的特殊条目 )。 That gitlink references the new SHA1 of the submodule.
该gitlink引用了子模块的新SHA1。
That means, each time the parent repo changes, the jenkins job needs to do a: 这意味着,每次父代仓库更改时,jenkins工作都需要执行以下操作:
git diff --name-only --diff-filter=M ${revision} HEAD
If the M (modified) list include the right submodule for that job, then (using a Parameterized Trigger Plugin ), trigger the right CI job. 如果M(已修改)列表包含该作业的右子模块,则(使用参数化触发器插件 )触发正确的CI作业。
The right CI job (one per submodule) will also monitor the main parent repo, will also not clone the submodules by default, except for the right one. 正确的CI作业(每个子模块一个)也将监视主父回复,默认情况下也不会克隆子模块,除了正确的子模块。
Its first step should follow " git submodule update specific submodule only " 它的第一步应该遵循“ git submodule update specific submodule only ”
git submodule update --init -- <specific relative path to submodule>
The rest of the job can build/test that specific submodule. 剩下的工作可以构建/测试特定的子模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.