如何在Bitbucket管道中使用git子模块?

时间:2018-11-02 15:58:05

标签: git ssh git-submodules bitbucket-pipelines

如何在Bitbucket管道中使用git子模块?

我正在使用Bitbucket管道来构建我的项目,并且在拉入子模块时遇到问题,我可能无法正确配置SSH密钥。

我所做的:

  1. 在我的计算机中创建了SSH密钥对。
  2. 在“设置/ 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

4 个答案:

答案 0 :(得分:6)

找到了解决方案。我必须将ssh公钥添加到Settings / Access Keys 不是 Settings / SSH Keys下的子模块存储库中。

答案 1 :(得分:5)

  1. 您的源存储库应包含文件MyProject/.gitmodules,其中包含子模块的路径:
[submodule "modules"]
    path = modules
    url = git@bitbucket.org:....git

[submodule "translations"]
    path = translations
    url = git@bitbucket.org:....git

2。

  • 打开存储库,您要在其中运行管道
  • 打开设置
  • 管道部分中,打开 SSH密钥
  • 点击生成密钥
  • 复制公共

现在您需要将ssh密钥添加到子模块存储库

  • 打开子模块存储库
  • 打开设置
  • 常规部分中,打开 访问键
  • 添加复制的ssh公钥

答案 2 :(得分:0)

这是另一个例子

  • 使用默认图片
  • 添加子模块
  • 仅压缩所需的文件,然后上传到bitbucket下载

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密钥方法。