简体   繁体   English

Jenkins 与 Git 存储库集成

[英]Jenkins integration with Git repository

  1. I have installed git 2.7 on my centos server.我已经在我的 centos 服务器上安装了 git 2.7。 and created repository at /srv/repo.git.并在 /srv/repo.git 创建了存储库。 i am able to clone this using the command ssh://user@serverIP:/srv/repo.git .我可以使用命令ssh://user@serverIP:/srv/repo.git

  2. I have installed jenkins & git on my local machine on Windows 10.我已经在 Windows 10 上的本地计算机上安装了 jenkins 和 git。

  3. Problem: Facing error while setup git repo with jenkins.Please see the screen-shot.问题:使用 jenkins 设置 git 存储库时遇到错误。请查看屏幕截图。 在此处输入图像描述

Error:错误:

Failed to connect to repository : Command "git.exe ls-remote -h -- ssh://username@server_ip:/srv/repo.git HEAD" returned status code 128:
stdout:
stderr: ssh: Could not resolve hostname server_ip: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Please help me on this.请帮助我。 Thanks in advance.提前致谢。

I find out the solution of this issue..there was an issue of authentication of jenkins with git server.我找到了这个问题的解决方案.. jenkins 与 git 服务器的身份验证问题。 Just resolve using below steps:只需使用以下步骤解决:

  1. Open git bash on local machine and generate public/private keyes using command: ssh-keygen在本地机器上打开 git bash 并使用命令生成公钥/私钥:ssh-keygen
  2. Copy the id_rsa.pub content to C:\Users\your_windows_user_name here.ssh\known_hosts将 id_rsa.pub 内容复制到 C:\Users\your_windows_user_name here.ssh\known_hosts
  3. In jenkins got to Source Code Management->Git->Credentials add在 jenkins 到 Source Code Management->Git->Credentials 添加
  4. In Jenkins select Kind->SSH Username with private key, Enter directly -> Paste the private generated private key here from the file在 Jenkins select Kind->SSH Username with private key, 直接输入 -> 从文件中粘贴生成的私钥到这里
  5. on Linux Server go to.ssh/authorized_keys and paste the C:\Users\your_windows_user_name here.ssh\id_rsa.pub file content here在 Linux 服务器 go 到 .ssh/authorized_keys 并将 C:\Users\your_windows_user_name 文件内容粘贴到此处。
  6. In jenkins project configuration go to the "Source code management" section and choose git->Repositary url-> paste this ssh://user@serverIP:/srv/repo.git In jenkins project configuration go to the "Source code management" section and choose git->Repositary url-> paste this ssh://user@serverIP:/srv/repo.git
  7. Select the Credentials which we create in step no. Select 我们在步骤号中创建的凭据。 3 & 4. 3 和 4。

You have to exchange 'server_ip' with the IP of your server.您必须与服务器的 IP 交换“server_ip”。

Username should to set to the correct one, too.用户名也应该设置为正确的。 You said that you can clone like this你说你可以这样克隆

ssh://user@serverIP:/srv/repo.git

But Jenkins is trying to clone like this但是 Jenkins 正试图像这样克隆

ssh://user@server_ip:/srv/repo.git

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

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