如何在 Gitlab CI 中使用 --remote 拉取子模块?
How to pull submodules with --remote within Gitlab CI?
我需要我的 Gitlab CI 使用 --remote
标志更新子模块,以便将 HEAD 设置为远程的 HEAD。经过一番谷歌搜索后,我发现我需要手动将 GIT_SUBMODULE_STRATEGY
设置为 none
和 运行 git submodule update --recursive --remote --init
:
variables:
GIT_STRATEGY: clone
GIT_SUBMODULE_STRATEGY: none
before_script:
- apk add git || ( apt-get update && apt-get -y install git )
- git submodule update --recursive --remote --init
test:build:
services:
- docker:dind
image: ubuntu
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
script:
- echo "done
不幸的是,我遇到了 CI 失败(名称已编辑):
$ git submodule update --recursive --remote --init
Submodule 'current_project_name/submodule_project_name' (ssh://git@gitlab.someserver.net:9931/someorg/submodule_project_name.git) registered for path 'current_project_name/submodule_project_name'
Cloning into '/builds/someorg/current_project_name/current_project_name/submodule_project_name'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'ssh://git@gitlab.someserver.net:9931/someorg/submodule_project_name.git' into submodule path '/builds/someorg/current_project_name/current_project_name/submodule_project_name' failed
Failed to clone 'current_project_name/submodule_project_name'. Retry scheduled
Cloning into '/builds/someorg/current_project_name/current_project_name/submodule_project_name'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'ssh://git@gitlab.someserver.net:9931/someorg/submodule_project_name.git' into submodule path '/builds/someorg/current_project_name/current_project_name/submodule_project_name' failed
Failed to clone 'current_project_name/submodule_project_name' a second time, aborting
我可以看到 CI 确实具有克隆 submodule_project_name
的权限,因为如果我设置 GIT_SUBMODULE_STRATEGY
例如到 recursive
,CI 设法拉了它(但它不是 --remote
,所以它没有按我想要的方式工作)。不幸的是,当我的 before_script
尝试这样做时,我遇到了错误。我怎样才能绕过它?
我 updating the ~/.ssh/.known_hosts
file, as in here。
当 fetching the submodules before the script 时不需要这样做(这不是您将 GIT_SUBMODULE_STRATEGY
设置为 NONE
时所做的)
With dind (Docker In Docker),还要考虑 this thread,关于私钥的 ssh-add,以及 .dockerini
/ .dockerenv
SSH 指令。
OP d33tah confirms :
I actually didn't add any key, assuming that since Gitlab CI's defaults can pull the key, I should be able to as well.
Then I found that docs say that I needed a deploy key and I added one
是:在 Gitlab 端添加 public 密钥是强制性的。
我需要我的 Gitlab CI 使用 --remote
标志更新子模块,以便将 HEAD 设置为远程的 HEAD。经过一番谷歌搜索后,我发现我需要手动将 GIT_SUBMODULE_STRATEGY
设置为 none
和 运行 git submodule update --recursive --remote --init
:
variables:
GIT_STRATEGY: clone
GIT_SUBMODULE_STRATEGY: none
before_script:
- apk add git || ( apt-get update && apt-get -y install git )
- git submodule update --recursive --remote --init
test:build:
services:
- docker:dind
image: ubuntu
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
script:
- echo "done
不幸的是,我遇到了 CI 失败(名称已编辑):
$ git submodule update --recursive --remote --init
Submodule 'current_project_name/submodule_project_name' (ssh://git@gitlab.someserver.net:9931/someorg/submodule_project_name.git) registered for path 'current_project_name/submodule_project_name'
Cloning into '/builds/someorg/current_project_name/current_project_name/submodule_project_name'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'ssh://git@gitlab.someserver.net:9931/someorg/submodule_project_name.git' into submodule path '/builds/someorg/current_project_name/current_project_name/submodule_project_name' failed
Failed to clone 'current_project_name/submodule_project_name'. Retry scheduled
Cloning into '/builds/someorg/current_project_name/current_project_name/submodule_project_name'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'ssh://git@gitlab.someserver.net:9931/someorg/submodule_project_name.git' into submodule path '/builds/someorg/current_project_name/current_project_name/submodule_project_name' failed
Failed to clone 'current_project_name/submodule_project_name' a second time, aborting
我可以看到 CI 确实具有克隆 submodule_project_name
的权限,因为如果我设置 GIT_SUBMODULE_STRATEGY
例如到 recursive
,CI 设法拉了它(但它不是 --remote
,所以它没有按我想要的方式工作)。不幸的是,当我的 before_script
尝试这样做时,我遇到了错误。我怎样才能绕过它?
我~/.ssh/.known_hosts
file, as in here。
当 fetching the submodules before the script 时不需要这样做(这不是您将 GIT_SUBMODULE_STRATEGY
设置为 NONE
时所做的)
With dind (Docker In Docker),还要考虑 this thread,关于私钥的 ssh-add,以及 .dockerini
/ .dockerenv
SSH 指令。
OP d33tah confirms
I actually didn't add any key, assuming that since Gitlab CI's defaults can pull the key, I should be able to as well.
Then I found that docs say that I needed a deploy key and I added one
是:在 Gitlab 端添加 public 密钥是强制性的。