git - 如何将多个私有源拉入 Azure 上的管道代理?
问题描述
我目前遇到了一个问题,即我能够从checkout
阶段中的一个私有 GitHub 源中提取,但由于缺乏访问权限而无法从管道中的后期提取另一个私有 GitHub 源。script
注意:两个 Repos 都是同一个组织的一部分。而且我已经将 Azure 应用程序连接到 GitHub 并可以访问所有存储库
在我的checkout
舞台上,我明确设置了persistCredentials: true
. 据我了解,这应该允许管道中的以下脚本使用在“获取源”的结帐中使用的 GitHub 凭据。
以下是失败的脚本示例:
- script: |
git clone --branch=username --single-branch
https://github.com/username/myRepo.git $(Agent.BuildDirectory)/myRepo
displayName: 'clone myRepo'
和输出:
Generating script.
[command]/bin/bash --noprofile --norc /Users/vsts/agent/2.140.2/work/_temp/cb2622cc-28e0-435a-bb98-154bdabf9641.sh
Cloning into '/Users/vsts/agent/2.140.2/work/1/myRepo'...
fatal: could not read Username for 'https://github.com': Device not configured
##[error]Bash exited with code '128'
解决方案
我也遇到了这个问题。我最终使用InstallSSHKey 任务安装了一个新的部署密钥。这些步骤非常简单。
- 在本地机器上生成一个密钥
ssh-keygen -f <key file name>
- 将私钥上传到Azure Pipelines 中的安全文件
- 使用获取 github 的公共 rsa 密钥
ssh-keyscan github.com
- 将以下内容添加到您的
azure-pipelines.yml
steps:
# ...
- task: InstallSSHKey@0
inputs:
knownHostsEntry: github.com ssh-rsa ... # Github's public key from ssh-keyscan
sshPublicKey: ssh-rsa ... # The public key (.pub) to key you generated
sshKeySecureFile: my_deploy_key # This is the name you gave the secure file when you uploaded it
- script: |
git clone git@github.com:user/repo.git
# ...
- 将公钥作为部署密钥添加到您需要在 github 中克隆的存储库中。
IIRC,您只能在一个存储库中使用部署密钥,因此可能需要为您需要克隆的每个存储库执行此操作。
PS。我发现 Azure Pipelines 的任务文档有点难以理解,但大多数任务都在这个 repo中定义。这是我使用的InstallSSHKey 任务的定义。
推荐阅读
- xcode - 在 x-code 中将资源添加到游乐场
- python - 如何在kivy中的两个屏幕类之间共享变量
- c++ - 在 while 循环中使用 std::cin 在添加多个数字时读取它们(循环不会终止)
- android - Android:如何将有关数字的数据从应用程序数据库提供给 android 手机应用程序 - 最近
- swift - SwiftUI:如果满足条件,如何为文本添加边框?
- image - 图像处理中的直方图均衡 python-Gonzalez e Woods
- javascript - 分配有会话属性的 JS 变量在页面重新加载之前为空
- java - 使用 Java SQL 时从运行行获取变量
- reactjs - React useContext 不会在状态更改时重新渲染
- flutter - 颤振:InternalLinkedHashMap
' 不是类型 'List 的子类型 在类型转换中