Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins with Tomcat - Failed to connect to repository : Could not init

Issue:

  • I have setup Jenkins v1.605 hosted with Apache Tomcat 7.0.59 on Windows 7 SP1 x64 behind a corporate proxy

  • I configured JDK, Git and maven installation paths in Jenkins. Also configured the proxy under the Advanced tab in Manage Plugins

  • I have a Java project on Eclipse that I have hosted on a Bitbucket repository using the EGit plugin and I am trying to connect it to Jenkins over https

  • I created a new job in Jenkins, added the repository URL (https://@bitbucket.org//.git) and added my credentials in the next step. This is where I get the following error:

Failed to connect to repository : Could not init D:\Work\apache-tomcat-7.0.59\temp\hudson4595160075978517187tmp

What I have tried:

I have checked ~20 SO questions and a lot of other websites in the last two days and implemented solutions others found helpful, but to no avail. Here's what I've tried:

  • Tried to clone the repository from Git Bash after configuring the http/https proxy in git (from this answer and this issue). The repository was cloned successfully, but Jenkins was not able to connect to it.

  • Double-checked the git installation path configuration in Jenkins (this and many other answers)

  • I downgraded the git and git client plugins from the latest versions to 1.5.0 and 1.0.7 respectively (from this and many other answers). After this, I entered the URL with my credentials (this answer), but got the same result. After this, I reverted to the latest versions.

  • I tried connecting to a GitHub repository, but faced the same issue

  • Tried to enter the repo URL in various formats (this and this answers)

  • I cleared the Tomcat temp folder and relaunched Jenkins with Tomcat (this answer), but it did not solve the issue

Can anyone please tell me if I'm missing something here? Should I perform some other steps while working behind a proxy? Or is it some other issue?

like image 770
Shahid M Zubair Avatar asked Mar 16 '23 17:03

Shahid M Zubair


2 Answers

I had this problem and investigated what's happening on the server using Process Monitor. I found this particular error which helped pinpoint the issue:

java.exe  CreateFile  C:\Users\...\AppData\Local\GitHub\PortableGit_blabla\cmd init C:\Users\...\AppData\Local\Temp\hudsonblablatmp NAME INVALID

Copying and pasting the command in a cmd window comes up with the C:\... is not recognized as an internal or external command... error.

What happens is that Jenkins is trying to execute the git init command in a temporary folder. But I noticed that there is no git executable in front of the init option in the problematic command on the server, which turns me to the Path to Git executable setting in Jenkins' configuration. I had configured it as is looks above (C:\...\cmd) but treated it as a simple path (i.e. chain of folders) and not specified the executable. Turns out that Jenkins is just getting that value and uses it as an absolute path to an executable. So I fixed that by appending \git.exe to it and voilà!

tl;dr

Make sure that the Path to Git executable in Jenkins' configurations is the absolute path to the executable, with the executable present in the path:

e.g. c:\Users\User\AppData\Local\GitHub\PortableGit_<guid>\cmd\git.exe

like image 151
CyberDude Avatar answered Mar 19 '23 07:03

CyberDude


This error is due to the non availability of Git on the server. This can be fixed by installing Git on the Jenkins server.

yum install -y git
like image 28
mebb Avatar answered Mar 19 '23 07:03

mebb