Azure DevOps Pipeline中Git SSH子模块克隆失败问题及解决
Azure DevOps Pipeline无法克隆SSH子模块的问题与解决
问题现象
主仓库可正常克隆,但无法克隆通过SSH URL添加的子模块(本地Fedora环境已配置SSH可正常操作),克隆失败提示:
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
尝试的操作
生成RSA密钥对后,使用Azure DevOps的InstallSSHKey@0任务安装密钥:
- task: InstallSSHKey@0 inputs: knownHostsEntry: '<entry>' sshPublicKey: '<public_key>' sshKeySecureFile: 'id_rsa'
该任务执行成功,输出如下:
/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
但执行以下命令初始化子模块仍失败:
GIT_SSH_COMMAND="ssh -v" git submodule update --init --recursive
调试日志
通过ssh -v的调试信息可见,已成功认证到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.
本地克隆时,git-upload-pack前的流程均正常,仅Pipeline中出现该问题。
解决方法
已解决:最终发现需将生成的SSH公钥添加到我的Azure DevOps账户中。起初误以为Azure机器间会自动完成认证,添加公钥后问题解决!
内容的提问来源于stack exchange,提问作者Jose Guilherme
相关产品推荐
相关产品推荐

