首页 > 解决方案 > 在私有 github 存储库中使用私有 github 子模块时,天蓝色 devops 管道失败

问题描述

我有两个私有 github 仓库,一个仓库用作另一个仓库的子模块。.git 模块看起来像这样

[submodule "submodule"]
    path = submodule
    url = ../submodule

我有一个两因素 SSO ,所以我使用 PAT 来访问这些存储库。

我在 AzureDevOps 中构建了这些,并且与我的 PAT.b 建立了服务连接,下面是我的管道 yaml。

resources:
  repositories:
    - repository: self
      type: GitHub
      name: myorg/main
      connection: github.com_connectionid
      pr:
        branches:
          include:
          - main
      trigger:
        batch: true
        branches:
          include:
          - main

pool:
  vmImage: 'ubuntu-latest'

steps:
  - checkout: self
    submodules: true
    persistCredentials: true

这样子模块检出失败。有这个错误

2021-05-02T17:01:06.3578223Z HEAD is now at 9560ded fix persist credentials
2021-05-02T17:01:06.3581105Z ##[command]git submodule sync
2021-05-02T17:01:06.3590245Z ##[command]git -c http.https://github.com.extraheader="AUTHORIZATION: basic ***" submodule update --init --force
2021-05-02T17:01:06.7063231Z Submodule 'submodule' (https://github.com/myorg/submodule) registered for path 'submodule'
2021-05-02T17:01:06.7065477Z Cloning into '/home/vsts/work/1/s/submodule'...
2021-05-02T17:01:06.7066269Z remote: Repository not found.
2021-05-02T17:01:06.7067185Z fatal: repository 'https://github.com/myorg/submodule/' not found
2021-05-02T17:01:06.7068915Z fatal: clone of 'https://github.com/myorg/submodule' into submodule path '/home/vsts/work/1/s/submodule' failed
2021-05-02T17:01:06.7070000Z Failed to clone 'submodule'. Retry scheduled
2021-05-02T17:01:06.7070925Z Cloning into '/home/vsts/work/1/s/submodule'...
2021-05-02T17:01:06.7071592Z remote: Repository not found.
2021-05-02T17:01:06.7072746Z fatal: repository 'https://github.com/myorg/submodule/' not found
2021-05-02T17:01:06.7073981Z fatal: clone of 'https://github.com/myorg/submodule' into submodule path '/home/vsts/work/1/s/submodule' failed
2021-05-02T17:01:06.7075750Z Failed to clone 'submodule' a second time, aborting
2021-05-02T17:01:06.7132523Z ##[error]Git submodule update failed with exit code: 1
2021-05-02T17:01:06.7332338Z ##[section]Finishing: Checkout myorg/main@main to s

更改 persistCredentials 无效。

在 URL 中添加完整路径无效。使用相同的服务连接成功签出主 repo。'main' 和 'submodule' 的名称已从原始名称更改。

标签: gitazure-devopsgit-submodulesazure-pipelines-yaml

解决方案


我现在有一个解决方法,我禁用子模块结帐并手动执行。这是受到类似问题的启发https://github.com/actions/checkout/issues/116#issuecomment-573880976

variables:
  - group: GIT_PAT    

- script: |
          env
          ls -la
          git config --file .gitmodules --get-regexp url | while read url; do
          git config --file=.gitmodules $(echo "$url" | sed -E "s/git@github.com:|https:\/\/github.com\//https:\/\/$(CI_PAT):$(CI_PAT)@github.com\//")
          done
          git submodule sync
          git submodule update --init --recursive
        displayName: checkout submodule

CI_PAT 作为机密存储在变量组 GIT_PAT 中。

这有效


推荐阅读