gitlab子模块foreach推送创建

时间:2019-08-21 17:32:46

标签: git gitlab gitlab-ci git-submodules

Gitlab提供了这种方法,可以将新项目直接推送到gitlab,而无需先在Web-gui上对其进行初始化。以下命令效果很好:

git push --set-upstream git@my.gitlab.com:username/project-name.git master

我想做同样的事情,但是要遍历新项目中的所有子模块。我正在尝试通过以下子模块foreach获取以下命令:

git submodule foreach --recursive 'sudo git push --set-upstream https://my.gitlab.com/namespace/$project-name.git master'

但是这样失败:

Entering 'sub-repo-1'
> GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Stopping at 'sub-repo-1'; script returned non-zero status.

在我的用例中,我有一个项目树,其中包含数百个要推送到gitlab的子模块。最终,我想将其集成到CI工作流程中,但首先要考虑的事情。

有什么想法为什么每个推送创建的子模块都不能在gitlab CI上运行?

1 个答案:

答案 0 :(得分:0)

通过反复试验,我解决了自己的问题。这是文件名,权限和回显问题。此命令有效。请注意,子模块foreach公开了$name变量。

git submodule foreach --recursive 'git push --set-upstream git@my.gitlab.com:root/`printf $name | sed "s/[^a-zA-Z0-9]/-/g"`.git master'