Jenkins:无法连接到Bitbucket Git存储库

时间:2018-12-11 04:52:45

标签: git jenkins github ssh

我正在尝试将jenkins连接到bitbucket git存储库。

当我在jenkins中指定存储库URL时,它将返回以下错误消息:

Failed to connect to repository : 
Command "git ls-remote -h <SSH_Git_url> HEAD" returned status code 128: stdout: stderr: Host key verification failed. 
fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

我已经使用Git Bash成功运行了上面的命令(运行jenkins),并且known_hosts文件具有正确的主机地址和端口。

我也用过 set git_ssh_command="ssh -i <ActualPathToPrivateKey>",然后运行上面的命令,以检查是否有帮助。

其他一些要点(不确定是否增加了这个问题,而是尝试提供尽可能多的信息):

a. The public\private keys were created using the `ssh-keygen` command in the c:\users\<UserName>\.ssh folder. 
b. The public key was copied and added as a read\write access key for the repository in bitbucket.
c. Jenkins runs as a windows service and logs on as a "Local service account".

我可能做错了什么?

更新:2018年12月11日:

git版本是2.17.1.windows.2。

我尝试了@VonC建议的选项,但出现以下相同错误。在“配置单个job =>凭据”下拉列表中没有显示任何内容。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

  

Jenkins作为Windows服务运行,并以“本地服务帐户”登录

这意味着在进行测试时,它可能无法访问与您帐户相同的环境变量。
确保在SSH Credentials plugin中注册您的ssh密钥。

并检查您的Git版本:如果是2.19.2,则ssh-keygen命令已将生成的密钥格式(从PEM更改为openssh):请参见“ Jenkins: what is the correct format for private key in Credentials”。