繁体   English   中英

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

[英]How to use git submodules with 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

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

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

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

2.

  • 打开存储库你想在哪里运行管道
  • 打开设置
  • PIPELINES部分打开SSH 密钥
  • 点击生成密钥
  • 复制公钥

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

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

这是另一个例子

  • 使用默认图像
  • 添加子模块
  • 只压缩需要的文件并上传到 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

如果您在主存储库中初始化了一个子模块,那么您可以在 bitbucket 管道步骤脚本中添加此命令:

- git submodule update --init --recursive

无需使用 SSH 密钥方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM