简体   繁体   English

设置jenkins git会返回“主机密钥验证失败”错误

[英]Setting jenkins git returns “Host key verification failed” error

I want to put one of my jenkins projects into source code management with git. 我想用git把我的一个jenkins项目放到源代码管理中。

However, when I typed git@gitlab.com:myGitlabAccount/myProjectName.git into Repository URL under Source Code Management tab in the project configuration page. 但是,当我在项目配置页面的源代码管理选项卡下键入git@gitlab.com:myGitlabAccount/myProjectName.git存储库URL时 I saw the following error message: 我看到以下错误消息:

Failed to connect to repository : Command "git.exe ls-remote -h git@gitlab.com:myGitlabAccount/myProjectName.git" 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.

There's no error message when I type git.exe ls-remote -h git@gitlab.com:myGitlabAccount/myProjectName.git under windows command line. 在Windows命令行下键入git.exe ls-remote -h git@gitlab.com:myGitlabAccount/myProjectName.git时没有错误消息。

I can git clone git@gitlab.com:myGitlabAccount/myProjectName.git successfully. 我可以成功git clone git@gitlab.com:myGitlabAccount/myProjectName.git

And I think that Jenkins Host key verification failed is a solution to my problem if I were a linux jenkins user. 如果我是一名Linux jenkins用户,我认为Jenkins Host密钥验证失败是我问题的解决方案。

But I use jenkins under windows environment, and I don't find any user called jenkins in windows. 但我在windows环境下使用jenkins,我在Windows中找不到任何名为jenkins的用户。

How can I switch to jenkins user and type git ls-remote -h git@bitbucket.org:person/projectmarket.git HEAD manually in windows environment? 如何在Windows环境中手动切换到jenkins用户并输入git ls-remote -h git@bitbucket.org:person/projectmarket.git HEAD

If you installed Jenkins per default as a Windows service, you can copy a file named "known_hosts" under the directory 如果您将Jenkins默认安装为Windows服务,则可以在目录下复制名为“known_hosts”的文件

C:\\Windows\\System32\\Config\\SystemProfile\\ .ssh C:\\ Windows \\ System32 \\ Config \\ SystemProfile \\ .ssh

This will be read by Jenkins then and allow it to access your Git server. 这将由Jenkins读取,然后允许它访问您的Git服务器。

在此输入图像描述

Because I installed jenkins as a windows service, I have to go to jenkins service page, and change its login account to the account I use to login windows. 因为我安装了jenkins作为Windows服务,所以我必须去jenkins服务页面,并将其登录帐户更改为我用来登录Windows的帐户。

In this way, jenkins can access the known_hosts file I used in my windows environment. 通过这种方式,jenkins可以访问我在windows环境中使用的known_hosts文件。

You need to generate ssh keys on your jenkins machine and add them to your gitlab account 您需要在jenkins机器上生成ssh密钥并将它们添加到您的gitlab帐户

If you are using windows open git bash and type the following: 如果您正在使用Windows打开git bash并键入以下内容:

# generate keys
ssh-keygen -t rsa

click ENTER on each step and if you already have a key you will get a warning that a certificate already exist. 点击ENTER每一步,如果你已经有一个键,你会得到一个警告,一个证书已经存在。

Now copy the public key and paste it under you gitlab account 现在复制公钥并将其粘贴到您的gitlab帐户下

# grab the key
cat ~/.ssh/id_rsa.pub

Login you your gitlab account and add this key (you will see ssh-keys on the top menu once logged in) 登录您的gitlab帐户并添加此密钥(登录后您将在顶部菜单上看到ssh-keys)

在此输入图像描述

One alternative which worked for me is to use HTTPS rather then SSH link under "Clone or Download tab". 对我有用的一个替代方法是在“克隆或下载选项卡”下使用HTTPS而不是SSH链接。 With SSH I am still seeing issue which i have to analyze more, but for time being HTTPS worked straight forward. 使用SSH我仍然看到问题,我必须分析更多,但暂时HTTPS工作直接。

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

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