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

trnvg8h3  于 12个月前  发布在  Jenkins
关注(0)|答案(9)|浏览(187)

我在Jenkins的一个项目中有一个子模块。我已经启用了高级设置来递归更新子模块。
当我运行构建时,我看到工作区包含子模块中的文件。问题是,它似乎是子模块的第一次修订。当我推送更改时(存储库托管在GitHub上),Jenkins似乎没有更新子模块以获得正确的更改。有人看过这个吗?

fv2wmkja

fv2wmkja1#

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

正如vikramvi所说:
Advanced sub-modules behavior >“Path of the reference repo to use during submodule update“,在此字段中添加子模块git url。

Owen B在评论中提到:
对于身份验证问题,现在有一个“使用来自父存储库的默认远程的凭据”选项
JENKINS-20941中可以看到:

5kgi1eie

5kgi1eie2#

这在Jenkins网站上的Git插件文档中的以下章节中有所介绍:Recursive submodules

  • 摘录 *

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

示例

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

然后选择“Recursively update submodules”:

vlf7wbxs

vlf7wbxs3#

你是否意识到你的Git仓库总是引用子模块的一个特定的修订版本?Jenkins不会自动更改版本。
如果你想使用子模块的更新版本,你必须在本地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

当你这样做的时候,Jenkins将在构建过程中检出子模块的完全相同的版本。Jenkins不会自行决定使用子模块的哪个版本。这是Git子模块和SVN外部模块之间的根本区别。
你可能想读一本关于子模块的好的参考书,例如。http://progit.org/book/ch6-6.html

u4vypkhs

u4vypkhs4#

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

问题:

使用凭据的初始克隆工作正常,但随后的submodule克隆因凭据不正确而失败。
1.自动高级子模块克隆:Source Code Management >> Additional Behaviours >> Advanced sub-modules behaviours:导致凭据错误。

  1. Execute Shell部分中的git submodule update --init也失败,并出现凭据错误。

解决方案:

我使用jenkins-1.574
1.检查Build Environment >> SSH Agent框。
1.选择正确的凭据(可能与Source Code Management部分中选择的凭据相同
1.更新Execute Shell部分中的子模块

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

这里有一个屏幕截图

ee7vknir

ee7vknir5#

看来我找到了解决办法:
我添加了一个构建步骤来执行以下shell命令:

git submodule foreach git checkout master
git submodule foreach git pull
yduiuuwa

yduiuuwa6#

如果你使用的是Jenkins Git模块,你可以将其设置为“在构建之前清除工作区”,这样它总是会得到正确的子模块。

vsikbqxv

vsikbqxv7#

我使用脚本流水线与结帐插件。如果你希望子模块与仓库中的子模块相同,只需关闭trackingSubmodules选项,如下所示:

checkout([$class: 'GitSCM', branches: [[name: '*/develop']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: false, reference: '', trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '[myCredentials]', url: 'https://git.myRepo.git']]])
368yc8dk

368yc8dk8#

在“高级子模块行为”中,选中“将跟踪子模块更新到分支的顶端”

w46czmvw

w46czmvw9#

我无法让scmGit与子模块一起工作。构建在本机git调用时失败,原因如下:
/usr/bin/git config --get submodule.. url”返回状态码1:
所以我丑陋的黑客解决方案是手动初始化子模块:

scmGit ...
sh 'git submodule add --force "<sub-path>" "<sub-name>"'

相关问题