如何在Bitbucket管道中使用git子模块?
我正在使用Bitbucket管道来构建我的项目,并且在拉入子模块时遇到问题,我可能无法正确配置SSH密钥。
我所做的:
构建错误:
Submodule 'dependencies/my-dependency' (git@bitbucket.org:mycompany/my-dependency.git) registered for path 'dependencies/my-dependency'
Cloning into 'dependencies/my-dependency'...
Warning: Permanently added the RSA host key for IP address '18.205.93.2' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Clone of 'git@bitbucket.org:mycompany/my-dependency.git' into submodule path 'dependencies/my-dependency' failed
我的yml文件
image:
name: myuser/my-image-name
username: $DOCKER_HUB_USERNAME
password: $DOCKER_HUB_PASSWORD
email: $DOCKER_HUB_EMAIL
pipelines:
branches:
pipelines-setup:
- step:
script:
- git submodule update --init
答案 0 :(得分:6)
找到了解决方案。我必须将ssh公钥添加到Settings / Access Keys
不是 Settings / SSH Keys
下的子模块存储库中。
答案 1 :(得分:5)
MyProject/.gitmodules
,其中包含子模块的路径:[submodule "modules"]
path = modules
url = git@bitbucket.org:....git
[submodule "translations"]
path = translations
url = git@bitbucket.org:....git
2。
现在您需要将ssh密钥添加到子模块存储库
答案 2 :(得分:0)
这是另一个例子
image: atlassian/default-image:2
pipelines:
default:
- step:
deployment: production
script:
- git submodule update --recursive --init
- apt-get update && apt-get install -y zip
- zip -r Test.zip . -x bitbucket-pipelines.yml *.git*
- pipe: atlassian/bitbucket-upload-file:0.1.3
variables:
BITBUCKET_USERNAME: $BITBUCKET_USERNAME
BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
FILENAME: Test.zip
答案 3 :(得分:0)
如果已在主存储库中初始化了子模块,则可以在bitbucket管道步骤脚本中添加以下命令:
- git submodule update --init --recursive
无需使用SSH密钥方法。