Why GIT Plugin in Jenkins is not able to connect to the GIT Repository? Why GIT Plugin in Jenkins is not able to connect to the GIT Repository? jenkins jenkins

Why GIT Plugin in Jenkins is not able to connect to the GIT Repository?


Today i also set up the jenkins with git repository, worked for me, hope this helps,

To connect git with jenkins do following steps :

STEP 1. After successfull installation of plugins create a new job like this:

1.create a Job name

2.checked the radio button of Build a maven software project

3.click OK

STEP 2. Now checked the radio button for Git enter the uri of your git repository.

STEP 3. If you will see the error like

Failed to connect to repository : Command "git ls-remote -h git@example.git HEAD" returned status code 128:stdout:stderr: fatal: 'git@example.git' does not appear to be a git repositoryfatal: The remote end hung up unexpectedly

You have to do some more configuration:

1.Go to to the terminal

2.Run this command : sudo visudo

3.Add %jenkins ALL=NOPASSWD: ALL in this file where sudo previlage is defined.and close the file.

4.login as jenkins user via command : sudo su jenkins

5.Create a .ssh directory in the jenkins home directory.

6.create the public private key pair like this.

Generating SSH Keys:

1: Check for SSH keys

First, we need to check for existing ssh keys on your computer. Open up Terminal and run:

cd ~/.ssh Checks to see if there is a directory named ".ssh" in your user directory

If it says "No such file or directory" go to step 2. Otherwise, you already have an existing keypair, and you can skip to step 3.

2: Generate a new SSH key

To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.

ssh-keygen -t rsa -C "your_email@example.com"

Creates a new ssh key, using the provided email as a label Generating public/private rsa key pair. Enter file in which to save the key (/home/you/.ssh/id_rsa):Now you need to enter a passphrase or file.press enter without to write any thing.

Which should give you something like this:

Your identification has been saved in /home/you/.ssh/id_rsa.

Your public key has been saved in /home/you/.ssh/id_rsa.pub. The key fingerprint is:

01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

3: Add your SSH key to GitHub

Go to your Account Settings

4 : Under Source Management tag,

       Build Triggers- Build whenever a SNAPSHOT dependency is built       Root POM-  /var/lib/jenkins/jobs/ProjectName/workspace/ProjectName/pom.xml

Under Execute Shell tag you can put your scripts to execute.

Finally Click on Build Now to create the build, Open console to check the status.


Before pulling the project, try to set the HTTP proxy in global configuration:

$> git config --global http.proxy http://mycom.example.com:80

If you need to provide a username and a password for your proxy, you can use:

$> git config --global http.proxy http://example.com\\<yourUsername>:<yourPassword>@<yourProxyServer>:80


Turned out it was a proxy issue.

While pulling the code from GIT using Jenkins it was setting the http_proxy to mycom.domain.com:80 (MASTER machine proxy) and this proxy was not required in the SLAVE machine.

So, I just added the GIT URL to No Proxy Host section (Manage Jenkins -> Manage Plugins -> Advanced -> HTTP Proxy Configuration -> Added GIT URL in No Proxy Host field) in Jenkins and now it is working fine.