gpt4 book ai didi

git - 从 azure pipeline check out git 子模块

转载 作者:行者123 更新时间:2023-12-02 22:50:41 24 4
gpt4 key购买 nike

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

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

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

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

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

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

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

最佳答案

Checkout git submodule from azure pipeline

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

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

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

请务必将“<BASIC_AUTH_TOKEN> ”替换为您的 Base64 编码 token 。

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

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

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 .

关于git - 从 azure pipeline check out git 子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64978039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com