从 azure pipeline 检出 git 子模块

Man*_*ons 9 git azure git-submodules azure-pipelines

我目前正在开发一条天蓝色的管道。在我的主 github 存储库(存储库 A)中,我添加了另一个 github 存储库作为子模块。(回购协议B)

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

stages:
- stage: checkout
  jobs:
  - job: checkout
    steps:
      - checkout: self
        submodules: true
        persistCredentials: true
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

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

如何通过天蓝色管道更新子模块?

Leo*_*SFT 9

从 azure pipeline 检出 git 子模块

如果 github 存储库(存储库 A)和子模块(存储库 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
Run Code Online (Sandbox Code Playgroud)

请务必将“ <BASIC_AUTH_TOKEN>”替换为您的 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
Run Code Online (Sandbox Code Playgroud)

从这篇文章中查看更多信息。


Von*_*onC 2

检查是否可以允许 Azure 脚本访问系统令牌,该令牌用于从构建和发布内部针对 VSTS 进行身份验证

steps:
- checkout: self
  persistCredentials: true
Run Code Online (Sandbox Code Playgroud)

这个答案对此进行了说明。

我想这个问题的出现是因为子模块存储库的性质:如果它是私有存储库,则需要克隆凭据。