Jenkins使用Git Submodule

项目的版本库在一些情况下需要引用其他的版本库,例如公用的代码库,可以在多个项目中调用,而公用库本身也是一个git的版本库,这个时候可以使用git子模组(Git Submodule)解决,Git Submodule允许将一个git repostory以目录的形式做为另一个git repostory的子目录。可以参考:https://segmentfault.com/a/1190000003076028

Jenkins用来做项目的持续集成,如果使用了Git Submodule,每次Jenkins更新版本库的时候还需要更新submodule的内容。

设置项目更新submodule

在项目的设置 -> 源码管理 -> git中,添加一个Additional Behaviours
图片描述

选择Recursively update submodules,会递归的更新Git Sbumodule中的内容。

开始构建,项目中出现一个错误出现:

hudson.plugins.git.GitException: Command "git.exe submodule update --init --recursive" returned status code 128:
stdout: 
stderr: Cloning into '...'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '....' into submodule path '....' failed

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1693)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:62)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$7.execute(CliGitAPIImpl.java:953)
    at hudson.plugins.git.extensions.impl.SubmoduleOption.onCheckoutCompleted(SubmoduleOption.java:90)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1098)
    at hudson.scm.SCM.checkout(SCM.java:485)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:607)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
    at hudson.model.Run.execute(Run.java:1738)
    at hudson.matrix.MatrixBuild.run(MatrixBuild.java:301)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:410)
Finished: FAILURE

Git Submodule的身份认证

上面错误产生的原因git submodule使用的是ssh方式管理repository,没有找到可以使用的ssh key做submodule的身份认证。
这个问题已经在Jenkins的官网上提了个issuehttps://issues.jenkins-ci.org/browse/JENKINS-20941
目前解决这个问题的正式版本还没有发布,只能使用beta的插件解决这个问题,需要两个插件:

1.git 2.5.0-beta5
2.git-client 1.20.0-beta3

Jenkins插件升级

在系统管理中,可以找到插件管理:
图片描述

这里面有两个选项,一个是直接上传插件,可以把git 2.5.0-beta5git-client 1.20.0-beta3下载到本地再直接上传,就可以完成插件更新。
也可以设置更新站点,更新插件(一般情况下这种方式不是太容易更新,原因你知道的)。

更新地址:

http://mirror.xmission.com/jenkins/updates/experimental/update-center.json

使用统一的身份验证

插件更新完成之后,回到项目配置中git的设置,会多出一个选项:
图片描述

User credentials from default remote of parent repository
意思是Git Submodule的repository会使用和主repository一样的验证,就是主repository使用的身份,选中之后,Git Submodule就可以正常更新了。
再次构建项目,可以看到submodule的更新信息:

....
 git submodule init # timeout=10
 > git submodule sync # timeout=10
 > git config --get remote.origin.url # timeout=10
 > git config --get-regexp ^submodule # timeout=10
 > git config --get submodule.test.url # timeout=10
 > git remote # timeout=10
 > git config --get remote.origin.url # timeout=10
using GIT_SSH to set credentials ...
 > git submodule update --init --recursive test
 ....

姜家志
尽力了!才有资格说运气不好。

尽力了!才有资格说运气不好。

2.3k 声望
148 粉丝
0 条评论
推荐阅读
gitlab-runner升级到最新版本
出现这个问题的原因是因为gitlab-runner的版本过低,当前gitlab-runner最新版本为:12.7.1解决办法:升级gitlab-runner为最新版本,先升级包:

姜家志阅读 5k

git 常用命令 记录
有错误和改进的地方望留言,谢谢 : )顺便推荐一下,git入门教程Git 教程图解 GitPro Git 2(中文版)Git 使用Git 使用规范流程Git 工作流程Commit message 和 Change log 编写指南全局设置git config --system //...

Luff阅读 3.2k

Aliyun-使用Docker方式安装Jenkins
之前自己在阿里云ECS上面安装了Jekins(安装jenkins的文章),最近因为服务器中了挖矿木马于是准备重新安装一下,但是想到每次安装jenkins都要手动安装jdk、maven、docker、kubectl,感觉好麻烦,于是使用官方推荐...

Awbeci2阅读 2.1k

Win10 安装Docker以及Jenkins(超级详细篇)
安装Docker下载地址:[链接] ,按照它的指引教程,无脑下一步即可。安装成功后电脑会重启。打开docker桌面端,会显示进入链接,下载WSL 安装包进行无脑安装即可。安装 Linux 内核更新包 (重启电脑)重启 Docker ...

九旬3阅读 1.1k

git/pip/easy_install/apt代理/源设置
在公司内网环境中,访问公网往往需要经过公司的代理,对于浏览器、IDE等开发工具,都提供了设置代理的配置,而git、pip、easy_install等CLI工具,则需要通过命令或配置文件进行代理设置;对于Python、Ubuntu、Mav...

乘着风1阅读 5.5k

低代码开发重要工具:jvs-logic(逻辑引擎)2.1.6版本功能清单
逻辑引擎是一种能够处理逻辑表达式的程序,它能够根据用户输入的表达式计算出表达式的值。在实际应用中,逻辑引擎通常被用于处理规则引擎、决策系统、业务规则配置等领域,具有广泛的应用前景。前面几期我们了解...

软件部长2阅读 434

被吐槽 GitHub仓 库太大,直接 600M 瘦身到 6M,这下舒服了
忙里偷闲学习了点技术写了点demo代码,打算提交到我那 2000Star 的Github仓库上,居然发现有5个Issues,最近的一条日期已经是2022/8/1了,以前我还真没留意过这些,我这人懒得很,本地代码提交成功基本就不管了。

程序员小富2阅读 1.4k评论 1

尽力了!才有资格说运气不好。

2.3k 声望
148 粉丝
宣传栏