简体   繁体   English

如何在Jenkins中无需克隆的情况下监听子模块更改

[英]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 两个问题

  • How do I tell Jenkins to trigger a build when a submodule gets updated, but not clone the submodule? 如何在子模块更新时告诉Jenkins触发构建,但不能克隆子模块? I need the main project code cloned instead, but Jenkins still needs to start the build only when the submodule gets updated. 我需要克隆主项目代码,但Jenkins仍然需要在子模块更新时才启动构建。 So let's say say submodule A gets updated (a new commit ism adE), it should trigger a build where the main project code gets cloned. 因此,假设说子模块A得到更新(一个新的提交ism adE),它应该触发一个构建,其中主项目代码被克隆。 The submodule is not cloned. 子模块未克隆。
  • How do I pull the latest changes from the submodule to the submodule directory after Jenkins clones the main project? 在Jenkins克隆主项目后,如何将子模块中的最新更改拉到子模块目录? Granted, the submodule directory will be at a detached head. 当然,子模块目录将位于一个独立的头部。 How do I pull the latest changes to the submodule from the most recent commit (I cannot use git submodule update because that does not pull the latest changes to the submodule). 如何从最近的提交中提取子模块的最新更改(我不能使用git子模块更新,因为这不会将最新的更改提取到子模块)。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM