Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to pull the code form GIT using GIT Plugin Jenkins and the job is running on a slave machine.

MASTER system has http_proxy=mycom.domain.com:80

and in SLAVE system there is no http_proxy defined.

Whenever I am doing git clone locally in the SLAVE machine it works perfectly, however from Jenkins I haven't been successful.

It is throwing the following error:

Building remotely on SLAVE in workspace /data/test
 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url https://github.domain.com/Project-Digital/Project-eCommerce.git # timeout=10
Fetching upstream changes from https://github.domain.com/Project-Digital/Project-eCommerce.git
 > /usr/bin/git --version # timeout=10
using GIT_ASKPASS to set credentials 
Setting http proxy: mycom.domain.com:80
 > /usr/bin/git fetch --tags --progress https://github.domain.com/Project-Digital/Project-eCommerce.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://github.domain.com/Project-Digital/Project-eCommerce.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:803)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1063)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1094)
    at hudson.scm.SCM.checkout(SCM.java:495)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1278)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:604)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
    at hudson.model.Run.execute(Run.java:1728)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:404)
Caused by: hudson.plugins.git.GitException: Command "/usr/bin/git fetch --tags --progress https://github.domain.com/Project-Digital/Project-eCommerce.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: error: Failed connect to github.build.ge.com:80; Operation now in progress while accessing https://github.domain.com/Project-Digital/Project-eCommerce.git/info/refs

Is it because the MASTER system trying to set http proxy which is not present in the SLAVE system?

If yes, how to prevent it?

Or, is there something else I am missing?

like image 973
ANIL Avatar asked Jan 19 '17 12:01

ANIL


2 Answers

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 [email protected] HEAD" returned status code 128: stdout: stderr: fatal: '[email protected]' does not appear to be a git repository fatal: 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 "[email protected]"

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 [email protected]

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.

like image 65
lazyborg Avatar answered Oct 11 '22 13:10

lazyborg


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

like image 26
Ala Eddine JEBALI Avatar answered Oct 11 '22 14:10

Ala Eddine JEBALI