配置
在.gitlab-ci.yml中配置一个全局变量GIT_SUBMODULE_STRATEGY
,告诉runner去下载git子模块。
variables:
GIT_SUBMODULE_STRATEGY: recursive
出现问题
运行pipeline报了类似错误fatal: could not read Username for 'https://gitlab.com': No such device or address
,具体信息如下:
Synchronizing submodule url for 'third_party/third_party_project'
Cloning into '/builds/mind/aiserver/third_party/third_party_project'...
fatal: could not read Username for 'https://gitlab.com': No such device or address
fatal: clone of 'https://gitlab.com/mind/my_project.git' into submodule path '/builds/mind/server/third_party/third_party_project' failed
Failed to clone 'third_party/third_party_project'. Retry scheduled
Cloning into '/builds/mind/server/third_party/third_party_project'...
fatal: could not read Username for 'https://gitlab.com': No such device or address
fatal: clone of 'https://gitlab.com/mind/third_party_project.git' into submodule path '/builds/mind/server/third_party/third_party_project' failed
Failed to clone 'third_party/third_party_project' a second time, aborting
大概意思就是克隆子模块时权限验证错误。
解决办法
在gitlab项目页面Settings > Repository > Deploy Tokens
中添加一个Deploy Token
然后拿到username和token
配置.gitmodules
[submodule "third_party/third_party_project"]
path = third_party/third_party_project
url = https://<username>:<token>@gitlab.com/mind/third_party_project.git
和配置成上图拿到的值。
结语
如果以上方法对你有帮助,就给作者点个赞鼓励一下吧!!!如果有错误或不明白的欢迎留言。