git - gitlab子模块foreach推送创建
问题描述
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 工作流程中,但首先要做的是。
为什么子模块 foreach push-to-create 在 gitlab CI 上不起作用的任何想法?
解决方案
通过反复试验,我解决了自己的问题。这是一个文件名、权限和回显问题。该命令有效。请注意,子模块 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'
推荐阅读
- kubernetes - 注入 istio envoy 后的 Hazelcast 问题
- javascript - Vue 2 的 Vue 3 传送
- c# - 当用户在表 1 中创建时,将用户名和 id 复制到表 2
- php - 我的代码是否足以防止 SQL 注入?
- r - autostsm stsm_estimate 错误:exo 必须是数据框或数据表
- android-studio - 创建新的密钥库 Android Studio
- java - 如何在 Java 中同步两个线程
- go - Buffo 写入 net.Conn 永久阻塞
- python - 使用python从url抓取和下载excel文件
- amazon-web-services - 为什么 terraform plan 或 terraform apply 使用与应使用不同的工作空间?