【问题标题】:Checkout git submodule from azure pipeline从 azure 管道签出 git 子模块
【发布时间】:2020-11-25 14:00:41
【问题描述】:

我目前正在开发一个 azure 管道。 在我的主要 github 存储库 (repo A) 中,我添加了另一个 github 存储库作为子模块。 (回购 B)

我的目标是使用以下 YAML 在管道开始处检查子模块:

stages:
- stage: checkout
  jobs:
  - job: checkout
    steps:
      - checkout: self
        submodules: true
        persistCredentials: true

然后尝试签出子模块,但以以下错误结束:

Cloning into '/home/vsts/work/1/s/devops-scripting'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
fatal: clone of 'https://github.com/sourcerepo/devops-scripting.git' into submodule path '/home/vsts/work/1/s/devops-scripting' failed

使用不正确的用户/密码似乎是一个问题 - 如果我正在推送,我可以简单地使用提供用户/密码参数,但这似乎不适用于签出。

如何通过 azure 管道更新子模块?

【问题讨论】:

    标签: git azure azure-pipelines git-submodules


    【解决方案1】:

    从 azure 管道中签出 git 子模块

    如果 github repo (repo A) 和子模块 (repo B) 在同一个 GitHub 组织中,则使用存储在 GitHub 服务连接中的令牌来访问源。

    如果没有,您可以改为使用自定义脚本步骤来获取子模块。首先,获取个人访问令牌 (PAT) 并在其前面加上 pat:。接下来,对该前缀字符串进行 base64 编码以创建基本身份验证令牌。最后,将此脚本添加到您的管道中:

    git -c http.https://<url of submodule repository>.extraheader="AUTHORIZATION: basic <BASE64_ENCODED_TOKEN_DESCRIBED_ABOVE>" submodule update --init --recursive
    

    请务必将“&lt;BASIC_AUTH_TOKEN&gt;”替换为您的 Base64 编码令牌。

    在您的项目或构建管道中使用秘密变量来存储您生成的基本身份验证令牌。使用该变量在上述 Git 命令中填充密钥。

    另一种解决方法,使用自定义脚本重用访问令牌以进行子模块同步:

    steps:
    - checkout: self
      submodules: false
      persistCredentials : true
    
    - powershell: |
        $header = "AUTHORIZATION: bearer $(System.AccessToken)"
        git -c http.extraheader="$header" submodule sync
        git -c http.extraheader="$header" submodule update --init --force --depth=1
    

    查看this post的更多信息。

    【讨论】:

    • 这似乎比我的回答更完整/准确。赞成。
    【解决方案2】:

    检查是否可以允许您的 Azure 脚本到 access the system token,即 used authenticate against VSTS from inside your builds and releases

    steps:
    - checkout: self
      persistCredentials: true
    

    this answer 对此进行了说明。

    我认为问题是由于子模块存储库的性质引起的:如果它是私有存储库,则需要克隆凭据。

    【讨论】:

      猜你喜欢
      • 2020-03-10
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      • 2021-08-26
      • 1970-01-01
      • 2021-03-28
      相关资源
      最近更新 更多