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

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.

Related

Git clone/push/pull of a remote share fails

a few of us use a bare repository on a network share ( u:\data\some_repo.git) and this works fine with the expected limitations
However, just recently I have been unable to perform any typical git activities associated with the bare respository: push pull clone.
All activities fail with:
fatal: 'u:\data\some_repo.git' does not appear to be a
git repository fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository
exists.
I do have access and I can browse this location fine. If I copy some_repo.git to my local machine and do a git clone /c/Temp/some_repo.git it works.
There is no latency issue, I have full access, I have tried prepending file:/// with no luck. a GIT_TRACE does not show anything
GIT_TRACE=1 git clone "/u/data/some_repo.git" 12:52:37.433340
exec-cmd.c:237 trace: resolved executable dir:
C:/STORAGE/Application/Git/mingw64/bin 12:52:37.435332 git.c:444
trace: built-in: git clone u:/data/some_repo.git Cloning into
'InternalTestInterface'... 12:52:38.129124 run-command.c:663
trace: run_command: unset GIT_DIR; 'git-upload-pack
'''u:/data/some_repo.git'''' 12:52:38.370091 exec-cmd.c:237
trace: resolved executable dir:
C:/STORAGE/Application/Git/mingw64/libexec/git-core 12:52:38.370091
git.c:444 trace: built-in: git upload-pack
u:/data/some_repo.git fatal: 'Hu:/data/some_repo.git' does not appear
to be a git repository fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository
exists.
Any idea how to resolve this
--update--
as requested, attempting to perform a git init:
/u/data/test.git
$ git init error: fstat on
//FQDN.com/site_###/Groups/data/test.git/.git/config failed: Invalid
argument fatal: could not set 'core.filemode' to 'false'
I have the exact same setup at work, with the same network drive (also named U:\!)
And I had the same issue at some point, apparently due to some background synchronisation/backup process which was keeping an handle on some of the files of the Git bare repository.
Try first to see if you can re-create a separate bare repo, for testing, and push to it:
git init U:\data\test.git
cd path\to\local\repo
git remote add origin2 U:\data\test.git
git push origin2 master

Jenkins can't find local git repository

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).

Can't get Jenkins to recognise a git repo

Trying to get Jenkins to run with Gradle etc. Please note that this is a Windows 10 OS. Not Linux.
I want to use a git repo on my local machine, under D:\temp\.git\. There is a file HEAD there.
On the "Source Code Management" page I enter the following in Repository URL:
file:///D:/temp/.git/
(NB I have played around a lot with the number (and type) of slashes here... nothing works)
The response comes:
Failed to connect to repository : Command "git.exe -c
core.askpass=true ls-remote -h file:///D:/temp/.git/ HEAD" returned
status code 128: stdout: stderr: fatal: '/D:/temp/.git/' does not
appear to be a git repository fatal: Could not read from remote
repository. Please make sure you have the correct access rights and
the repository exists.
I note that it says "from remote repository". Just wondering if it might be a question of tweaking something somewhere to specify a local repository... ?
Plus I also then tried running this same command at a DOS prompt without and then with Administrator rights:
D:\temp>git.exe -c core.askpass=true ls-remote -h file:///D:/temp/.git/HEAD fatal: Invalid gitfile format:
D:/temp/.git/HEAD fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
... which is puzzling. "invalid gitfile format" - what's that about? Plus the "access rights" thing: could it be that this is happening due to some nonsense to do with Windows UAC? But even with Admin rights I get the same message.
A bit later:
This command works at the command prompt, including as a non-administrator, if you omit the word "HEAD":
D:>git.exe -c core.askpass=true ls-remote -h file:///D:/temp
a4ca18f7b218ef57b07f8dceef89ab6bdb5839a6 refs/heads/master
D:>git.exe -c core.askpass=true ls-remote -h file:///D:/temp/.git
a4ca18f7b218ef57b07f8dceef89ab6bdb5839a6 refs/heads/master
In your case, you don't want to configure a Git repository to track. Because you are working locally (only), it would be sufficient to configure Custom Workspace to point to your repository (General -> Advanced).
This would be D:\temp, not D:\temp\.git, because the .git directory is merely where Git keeps its information about your repository.

Git remote server Push fails

After cloning a Git repo from my remote server, I have committed some changes on my local copy. I'd like to push these changes back to the remote server, but I'm getting an error message that yields no useful information:
fatal: read error: Invalid argument
(Ps. both the server and the local repo are running in Windows environments)
I have tried:
git push
git push origin
git push origin master
A push through the GUI version of GIT yields the same useful error message.
EDIT
After setting the Environment variable GIT_TRACE=1, I get slightly more output:
C:\repo>git push --verbose
setup: git_dir: .git
setup: worktree: C:/repo
setup: cwd: C:/repo
setup: prefix: (null)
trace: built-in: git 'push' '--verbose'
Pushing to git://MYSERVER.MYCOMPANY.net/repo
fatal: read error: Invalid argument
Any thoughts?
Looks like you're running in a plain cmd.exe terminal instead of msysgit's bash terminal. Much of git relies on shell scripts; thus, you need to run in a bash terminal instead of cmd.exe.
Are you sure the server is configured correctly, has your SSH key, etc? Did you home-brew the Git server or is this something like git-hub / assembla ?

How to stop git via ssh on windows from resolving the wrong path?

I have a windows 2003 box with an ssh server setup. I have msysgit (git version 1.6.2) installed both locally and on the server.
The server has the following absolute path to my repos:
e:\vc\git\myrepo.git
when a user logs in he/she will be put in the following working directory:
e:\vc\git\
When running the following cmd on my dev machine:
git clone ssh://myuser#myip/myrepo.git testrepo
I get the following error:
fatal: ''/myrepo.git'' does not appear to be a git repository
According to my ssh logs it appears that git is executing this cmd on the server:
'cmd.exe /c git-upload-pack '/myrepo.git''
Executing that command locally (on the server) fails for the same reason. I'm thinking the problem is related to git prefixing the path with a '/'. How do I tell git not to do this? Should this be working?
Note: git-upload-pack is working because I added \gitinstallpath\libexec\git-core to the path. Apparently this is a bug and will be fixed in the future, this was my work around.
I resolved this by switching my ssh server from winssh to openssh (via the cygwin layer). I was able to connect fine (as noted above) using winsshd, but winsshd wasn't correctly handling paths prefixed with "/". I could probably get winsshd to work, but switching to cygwin and openssh was faster.
Here's a good blog post to kick start the setup if your in a similar situation:
Have you tried the following?
git clone ssh://myuser#myip/myrepo testrepo
Note the removal of ".git" from the end of the SSH path. You only need that suffix at the end if the remote directory name has it.
Also, have you tried any other SSH URL format? To use a relative path, you can try:
git clone ssh://myuser#myip/~/myrepo testrepo
See the git clone man page for details on other URL formats.
If somebody still interested in workaround:
The problem is - cmd.exe doesn't understand single-quoted parameters. So we use sh instead.
Create file gup.sh with line
git-upload-pack.exe $*
and grp.sh with
git-receive-pack.exe $*
on server!
Then run:
git clone -u 'sh gup.sh' ssh://myuser#myip/e/vc/git/myrepo.git testrepo
git config remote.origin.uploadpack 'sh gup.sh'
git config remote.origin.receivepack 'sh grp.sh'

Resources