简体   繁体   English

git 无法在 azure devops 管道中使用 ssh 克隆子模块

[英]git fails to clone submodule with ssh in azure devops pipeline

I'm trying to use the Azure DevOps pipeline.我正在尝试使用 Azure DevOps 管道。 The main repository the pipeline is supposed to run on is cloned just fine, except that I can't get to clone it's submodules.管道应该运行的主存储库被克隆得很好,除了我无法克隆它的子模块。 The submodules are added using SSH URLs because that's what is set up in my computer.使用 SSH URL 添加子模块,因为这是在我的计算机中设置的。

The cloning process fails with:克隆过程失败并显示:

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@ssh.dev.azure.com:v3/<rest_of_link>' into submodule path '/home/vsts/work/1/s/Modules' failed
Failed to clone 'Modules' a second time, aborting

So, since I'm using SSH, I've gone ahead and created a pair of RSA keys and I'm using Azure's own task to install it, as shown below:因此,由于我使用的是 SSH,因此我已经创建了一对 RSA 密钥,并且我正在使用 Azure 自己的任务来安装它,如下所示:

- task: InstallSSHKey@0
  inputs:
    knownHostsEntry: '<entry>'
    sshPublicKey: '<public_key>'
    sshKeySecureFile: 'id_rsa'

It succeeds with the following output:它通过以下 output 成功:

/usr/bin/ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-XXXXXXFGcDdd/agent.1614; export SSH_AUTH_SOCK;
SSH_AGENT_PID=1615; export SSH_AGENT_PID;
echo Agent pid 1615;
/usr/bin/ssh-add -L
The agent has no identities.
/usr/bin/ssh-add /home/vsts/work/_temp/id_rsa
Identity added: /home/vsts/work/_temp/id_rsa (jose@42we-desktop)
/usr/bin/ssh-add
Finishing: InstallSSHKey

Great, right?太好了,对吧? Except that if I try to initialize the submodules with:除了如果我尝试用以下方法初始化子模块:

GIT_SSH_COMMAND="ssh -v" git submodule update --init --recursive

It still fails.它仍然失败。

By looking at the extra information supplied through the usage of the -v flag, I can see that it initially accepts the key, and even says Authenticated to ssh.dev.azure.com , only to then fail after git-upload-pack通过查看通过使用 -v 标志提供的额外信息,我可以看到它最初接受密钥,甚至说Authenticated to ssh.dev.azure.com ,然后在git-upload-pack之后失败

debug1: Authentications that can continue: password,publickey
debug1: Next authentication method: publickey
debug1: Offering public key: <key> RSA SHA256 <key> agent
debug1: Server accepts key: <key> RSA SHA256 <key> agent
Authenticated to ssh.dev.azure.com ([20.125.155.0]:22) using "publickey".
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: Sending environment.
debug1: channel 0: setting env GIT_PROTOCOL = "version=2"
debug1: channel 0: setting env LANG = "C.UTF-8"
debug1: Sending command: git-upload-pack 'v3/name/project/repo'
remote: Public key authentication failed.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3592, received 2304 bytes, in 2.1 seconds
Bytes per second: sent 1725.1, received 1106.5
debug1: Exit status 2
fatal: Could not read from remote repository.

Why does it fail??为什么会失败?? It really doesn't make sense in my head, and the output I can see if I clone in my computer (running Fedora) is the same until the "git-upload-pack".这在我的脑海中真的没有意义,我可以看到如果我在我的计算机(运行 Fedora)中克隆的 output 是相同的,直到“git-upload-pack”。

SOLVED SOLVED SOLVED SOLVED解决了 解决了 解决了解决了

Turns out I needed to add the generated SSH key to my account as well.原来我还需要将生成的 SSH 密钥添加到我的帐户中。 I didn't think this made sense at first because the authentication should happen between azure machines itself... either way.一开始我认为这没有意义,因为身份验证应该在 azure 机器本身之间进行……无论哪种方式。 It's done and it works!它已经完成并且有效!

Turns out I needed to add the generated SSH key to my account as well.原来我还需要将生成的 SSH 密钥添加到我的帐户中。 I didn't think this made sense at first because the authentication should happen between azure machines itself... either way.一开始我认为这没有意义,因为身份验证应该在 azure 机器本身之间进行……无论哪种方式。 It's done and it works!它已经完成并且有效!

After you've generated a key pair, adding the private key to Azure's library and the public to the YAML script, you also need to add the public key to your own personal access keys in your azure devops profile.生成密钥对后,将私钥添加到 Azure 库,将公钥添加到 YAML 脚本,您还需要将公钥添加到 azure devops 配置文件中您自己的个人访问密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM