Jenkins can't find local git repository - windows

I am currently installaing a pipeline for my Visual Studio projects with Jenkins (on Windows).
I installed the Git Bash and Jenkins successfully, but when I generate a new Jenkins project I need to give a Repository URL. I entered the path to my project and got the following message:
Failed to connect to repository : Error performing command: git.exe
ls-remote -h file:///Users/myusername/Documents/Visual Studio
2015/Projects/QtTestApplication HEAD
I already searched for a solution and changed the user from Jenkins to the admin:
Jenkins configuration of git plugin
I double-checked the userchange in the Jenkins systeminformations (it's really running on the admin).
However i still get the same error as before and I'm not quite sure what to enter in this form.
I already tried "escaping" the whitespaces like this:
Failed to connect to repository : Error performing command: git.exe
ls-remote -h file:///Users/myusername/Documents/Visual\ Studio\
2015/Projects/QtTestApplication HEAD
EDIT: Solution Part 1
I found out, that git was not found by Jenkins and that i had to add it manually to it (edit the PATH variable).

Related

Jenkins git authentication failed with correct credentials on Windows

I'm currently using Jenkins on Windows 10, and using git as version control system.
Although I provided correct repository URL and credential, I cannot use jenkins with error below.
Failed to connect to repository : Command "git.exe ls-remote -h REPOSITORY_URL HEAD" returned status code 128:
stdout:
stderr: git#URL: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Credential and URL doesn't seems wrong, since this build success previously with same credential. The only change after successful build was one line in build script.
git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe
After I success with this script, git setting keeps failed. Is there any problem with that line? And how can I fix it?
EDIT
Problem solved! For anyone who has same problem, it was problem with the system user! Since ssh key stores in each user space, jenkins cannot detect where the ssh key located. Therefore, go to 'service' in windows, and change user of jenkins service to the user who has correct ssh key. It solved my problem!
Seems there is some problem in Jenkins.
It cannot locate OpenSSH folder in System32, and so that I cannot get log with it.
That would explain why the main Jenkins controller (aka "master" in old terminology) cannot contact the Git repository (assuming an SSH URL here, with technical remote user account "git")
Try and remove that git configuration to see if the error persists: Git should fall back to its own ssh.exe, packaged with Git For Windows.
As noted by the OP, this only works if said Jenkins is run as a user account, not as the system account.
Only then will it be able to access the %USERPROFILE%\.ssh folder.

git plugin on windows command fails from Jenkins, succeeds in shell [duplicate]

This question already has answers here:
Unable to get Jenkins and Git to play nice
(2 answers)
Closed 7 years ago.
I'm setting up Jenkins on my windows build machine, with the Git Plugin. I'm using a directory on a network drive Z: as the git repository for now. I enter "z:\my\repo\path" for the Repository URL, and I get:
Failed to connect to repository : Command "git.exe -c core.askpass=true ls-remote -h z:\my\repo\path HEAD" returned status code 128:
stdout:
stderr: fatal: 'z:\my\repo\path' does not appear to be a git repository
fatal: Could not read from remote repository.
Yet if I open a fresh command prompt and type that command, it works without error (and also no output):
> git.exe -c core.askpass=true ls-remote -h z:\my\repo\path HEAD
>
What may possibly be the issue? I am not even sure where to begin. I've set the PATH and GIT_HOME system environment variables and restarted Jenkins, so clearly it is finding the executable.
I've tried the file:///-style path and had the same results.
Output of the manual command with GIT_CURL_VERBOSE=1 and GIT_TRACE=1 set:
15:43:24.905801 git.c:348 trace: built-in: git 'ls-remote' '-h' 'z:\\my\\repo\\path' 'HEAD'
15:43:24.905801 run-command.c:343 trace: run_command: 'git-upload-pack '\''z:\\my\\repo\\path'\'''
I believe the problem could be around correctly setting up the SSH keys.
First suggestion - UNC path for the repo
Can you try using the file://// format for the repo instead of windows path?
If it's a share try using git clone file:////<host>/<share>/<path> instead.
Please use this as reference.
Second suggestion - SSH Keys
From https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin- :
(though the error is different that what you have)
Some windows fun
If you did everything, you should now have a ~/.ssh folder
(c:\Users\Bob.ssh for instance) and this folder contains your keys.
At that point, you may even be able to manually (from the console),
clone your repository but Jenkins keeps failing with something like
this:
code 128: Cloning into C:\Program Files\Jenkins\jobs\PG3\workspace...
fatal:
The remote end hung up unexpectedly
If you run into this issue, you may need to copy the id_rsa* files
from your ~./.ssh to another folder. Find your git.exe and check if
there is an .ssh folder there. If so, copy ~./ssh/id_rsa* to this
folder and try again.

Location of Git Executable for Jenkins on Windows

Which is the correct installation directory for Jenkins to use? Here are the options I have tried and the results I have seen.
C:\Git\bin\git.exe
C:\Git\cmd\git
same as above
C:\Git\cmd\gitk.cmd
If I continue and ask the job to build here is the console output.
Started by an SCM change
Building in workspace C:\Jenkins\workspace\git_test
Checkout:git_test / C:\Jenkins\workspace\git_test - hudson.remoting.LocalChannel#12f2468
Using strategy: Default
Cloning the remote Git repository
Cloning repository ssh:///jenkins#xxxx.yyyyyyyyy.com:test.git
git --version
Process leaked file descriptors. See http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build for more information
Fetching upstream changes from origin
Seen 0 remote branches
No candidate revisions
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
Finished: FAILURE
Since they all result in one error or another its not clear which one is correct.
This is not a problem with git not being found but that putty has not yet been told that it can trust the ssh-key presented by the repository sshd server.
Run a manual git command first on the Jenkins server, so you can say yes to accept the host key, and then try again.

Jenkins configuration of git plugin

I get this error when configuring git repo in a new jenkins project:
Failed to connect to repository : Error performing command: ls-remote -h file:///c:\Dev\git\rx HEAD
I have a local git repo on my windows machine and cloning the same path from command prompt works on the same machine. I don't know what could be the problem (git.exe is on system path)
Windows installs Jenkins as a service. But it runs the Jenkins service under different user permissions that don't have access to GIT. You can follow this link to find the user that Jenkins runs under. http://antagonisticpleiotropy.blogspot.com/2012/08/running-jenkins-in-windows-with-regular.html
For example. My local user name on my windows is "nathandrewsire", exclude the quotes. Open windows services manager (either cmd and c:\services.msc, OR use windows key + R). Enable Log On > This account:. Then type in .\username (e.g. .\nathandrewsire). Then restart the service and you will have access to GIT from Jenkins builds.
I also found a snippet for windows shell command that will output the user to verify it.
echo %PATH%
echo %USERDOMAIN%\%USERNAME%
http://antagonisticpleiotropy.blogspot.com/2012/08/running-jenkins-in-windows-with-regular.html
Linux
If you're using Linux, this error can also be caused from not enabling share on your Git repo. Linux jenkins user won't be able to access Git report under another user unless....
git --bare init --shared=group
Also, your jenkins user and Git repo user must belong to the same group for file permission access. There's other alternatives to that like messing with umasks and ACL's but setting up a linux group for your two users is the easiest way.
Make sure NOT TO OVERWRITE your Git repo with the bare init command. If you already have a Git repo, you'll need to setup/move to a new one with the shared option. I didn't see a way to convert existing repos to shared because I am guessing the files would all need to be updated?
NOTE***
I used VMWare Workstation shared folders to build on a windows guest. Jenkins needs the following format when entering the Git repo.
//vmware-host/Shared Folders/vm-share/ridcyDevelopment.git/
Unable to get Jenkins and Git to play nice

Windows, Git and Jenkins

I'm just starting to look at Jenkins CI on my Windows 7 machine.
I thought for a first test I would create a git repo on my localhost which is aliased to
http://tests.local/jenkins/local
I setup a job in Jenkins, selected Git under source code management and added http://tests.local/jenkins/local.git as the Repository URL
When the job runs it fails with the error
ERROR: Error cloning remote repo 'origin' : Could not clone http://tests.local/jenkins/local.git
Is this a git issue or a Jenkins issue and how can I fix it?
Thanks
Have you run git update-server-info in your repo? This is needed if you want to clone/fetch via http. Run git help update-server-info or see online documentation here for more details.

Resources