Git 子模块未在 Jenkins 构建中更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9953299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:20:44  来源:igfitidea点击:

Git submodules not updating in Jenkins build

gitjenkinsgit-submodules

提问by Ben

I have a submodule in a project in Jenkins. I've enabled the advanced setting to recursively update submodules.

我在 Jenkins 的一个项目中有一个子模块。我已启用高级设置以递归更新子模块。

When I run the build, I see that the workspace has the files from the submodule. The problem is, it seems to be the first revision of the submodule. When I push changes (repository hosted on GitHub) Jenkins doesn't seem to update the submodule to get the right changes. Has anyone ever seen this?

当我运行构建时,我看到工作区包含来自子模块的文件。问题是,它似乎是子模块的第一次修订。当我推送更改(托管在 GitHub 上的存储库)时,Jenkins 似乎没有更新子模块以获得正确的更改。有没有人见过这个?

采纳答案by Ben

It looks like I found a solution:

看起来我找到了解决方案:

I added a build step to execute the following shell commands:

我添加了一个构建步骤来执行以下 shell 命令:

git submodule foreach git checkout master
git submodule foreach git pull

回答by VonC

Note that the Jenkins Git plugin 2.0will have "advance submodule behaviors", which should ensure proper updates of the submodules:

请注意,Jenkins Git 插件 2.0将具有“高级子模块行为”,这应确保子模块的正确更新:

git 2.0

混帐 2.0

As commentedby vikramvi:

正如评论vikramvi

Advanced sub-modules behavior> "Path of the reference repo to use during submodule update" against this field , add submodule git url.

Advanced sub-modules behavior> " Path of the reference repo to use during submodule update"针对此字段,添加子模块 git url。

Path

小路



Owen Bmentions in the comments:

Owen B在评论中提到:

For the authentication issue, there's now a "Use credentials from default remote of parent repository" option

对于身份验证问题,现在有一个“使用来自父存储库默认远程的凭据”选项

Seen here in JENKINS-20941:

JENKINS-20941 中看到

https://issues.jenkins-ci.org/secure/attachment/33245/Screen%20Shot%202016-07-08%20at%2010.09.17.png

https://issues.jenkins-ci.org/secure/attachment/33245/Screen%20Shot%202016-07-08%20at%2010.09.17.png

回答by slm

This is covered in the Git Plugin documentation on the Jenkins site under the section: Recursive submodules.

这在 Jenkins 站点上的 Git 插件文档中的以下部分进行了介绍:递归子模块

excerpt摘抄

The GIT plugin supports repositories with submodules which in turn have submodules themselves. This must be turned on though: in Job Configuration-> Section Source Code Management, Git-> Advanced Button(under Branches to build) -> Recursively update submodules.

GIT 插件支持带有子模块的存储库,而子模块本身又具有子模块。但这必须打开:在Job Configuration-> Section Source Code ManagementGit-> Advanced Button(在 Branches to build 下)-> Recursively update submodules

Example

例子

From the configuration screen of your job, in the Source Code Management section, pull the Addbutton down select "Advanced sub-modules behavior".

在作业的配置屏幕中,在“源代码管理”部分,将“添加”按钮下拉选择“高级子模块行为”。

   s1

   s1

                                 s2

                                 s2

Then select "Recursively update submodules":

然后选择“递归更新子模块”:

   s3

   s3

回答by sti

Are you aware that your Git repository always refers to a particular revisionof a submodule? Jenkins is not going to automatically change the revision.

您是否知道您的 Git 存储库总是引用子模块的特定修订版?Jenkins 不会自动更改修订版。

If you want to take a newer revision of the submodule into use, you have to do this in your local Git repository:

如果要使用子模块的更新版本,则必须在本地 Git 存储库中执行此操作:

cd submoduledir
git pull
cd ..
git add submoduledir
git commit -m 'Updated to latest revision of submoduledir'
git push # Go and watch Jenkins build with the new revision of the submodule

When you do it like this, Jenkins will check out the exact same revision of the submodule during the build. Jenkins does not on its own decide which revision of the submodule to use. This is the fundamental difference between Git submodules and SVN externals.

当您这样做时,Jenkins 将在构建期间检查子模块的完全相同的修订版。Jenkins 不会自行决定使用子模块的哪个版本。这是 Git 子模块和 SVN 外部模块之间的根本区别。

You might want to read a good reference on submodules, e.g. http://progit.org/book/ch6-6.html.

您可能想阅读有关子模块的良好参考,例如http://progit.org/book/ch6-6.html

回答by potench

Finally stumbled on a way to do this and it's simple.

最后偶然发现了一种方法来做到这一点,这很简单。

The Issue:

问题:

The initial clone with credentials works fine but subsequent submodulecloning fails with incorrect credentials.

带有凭据的初始克隆工作正常,但随后的submodule克隆因凭据不正确而失败。

  1. Automatic advanced sub-module cloning: Source Code Management >> Additional Behaviours >> Advanced sub-modules behaviours: results in credential error.
  2. git submodule update --initin the Execute Shellsection also fails with credentials error.
  1. 自动高级子模块克隆Source Code Management >> Additional Behaviours >> Advanced sub-modules behaviours::导致凭据错误。
  2. git submodule update --init在该Execute Shell部分中也因凭据错误而失败。

The Solution:

解决方案:

I'm using jenkins-1.574.

我正在使用jenkins-1.574.

  1. Check the Build Environment >> SSH Agentbox.
  2. Select the correct credentials (probably the same as selected in Source Code Managementsection
  3. Update submodules in the Execute Shellsection

    git submodule sync
    git submodule update --init --recursive
    
  1. 选中该Build Environment >> SSH Agent框。
  2. 选择正确的凭据(可能与Source Code Management部分中选择的相同)
  3. 更新Execute Shell部分中的子模块

    git submodule sync
    git submodule update --init --recursive
    

Here's a screen shotenter image description here

这是屏幕截图在此处输入图片说明

回答by Amin Y

If you are using Jenkins Git module, you can set it to "Wipe out workspace before build", this way it will always gets the correct sub module.

如果您正在使用 Jenkins Git 模块,您可以将其设置为“在构建之前擦除工作区”,这样它始终会获得正确的子模块。