Can't get Jenkins to recognise a git repo - windows

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.

Related

go get url from github on my Apple MAC is not working on a private repository in company

I'm on a Apple MAC Laptop, go get command is not working.
I have normal git access, I can git clone and git commit and git push. Why does this go get command not work?
temp % go get github.com/MYCOMPANY/myproject
go get: module github.com/MYCOMPANY/myproject: git ls-remote -q origin in /Users/someuser/go/pkg/mod/cache/vcs/1872293eea4df8de643499713e2d8621a72624bb2514a7a88c1182d1869ef891: exit status 128:
ssh: Could not resolve hostname github.com:MYCOMPANY: nodename nor servname provided, or not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
temp % go get github.com/MYCOMPANY/myproject
go get: module github.com/MYCOMPANY/myproject: git ls-remote -q origin in /Users/someuser/go/pkg/mod/cache/vcs/1872293eea4df8de643499713e2d8621a72624bb2514a7a88c1182d1869ef891: exit status 128:
ssh: Could not resolve hostname github.com:MYCOMPANY: nodename nor servname provided, or not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
This is what works for me, based on #elulcao
go env -w GOPRIVATE=github.com/COMPANYNAME
git config --global --add url."git#github.com:".insteadOf "https://github.com/"
Then I can do
go mod download
In the projects git folder or go get
'go get' by default does not support private repositories. It only supports public repos.
If you want to get private repos please refer to this link

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.

Setting up and accessing git on windows 2012

I am using the following computers.
Local machine: Windows 10. I also have windows 7 machines here, but not really using them.
Windows Server 2012 r2 (not in the same physical location). This is not a production server, it's just a server I use for hosting various scripts.
I am currently just accessing the windows server with the IP address. However, if it some how makes this easier, I can assign it a static IP link it to a subdomain.
Obviously using the real IP of the server, but for the sake of this post, I'm using 1.1.1.1
I've set up git on the windows server. I followed:
https://www.server-world.info/en/note?os=Windows_Server_2012&p=openssh
I just deleted all the repositories I was testing with, so I could go through it step by step here in hopes someone can point out where I've gone wrong.
I created a user on the server, named 'kannkor', and assigned it a password.
I am currently RDC (remote desktop connection) into the server. So I can do anything, verify from there if I need.
I have putty open, and the connection type is "ssh", the host name is the IP of the server, on port 22.
It asks me:
login as:
I type in "kannkor"
It then asks:
kannkor#1.1.1.1's password:
I type it in.
It takes me to:
kannkor#computername C:\Users\kannkor>
I'd like the repositories to be on the d drive.
I can change directories:
I create a new folder:
d:
mkdir repos
cd repos
From the RDC, I can verify the repos folder is now created under D:
Going through a mental checklist, this means my username/password/permissions to that drive/folder are set.
At this stage, I feel like I've followed 100 walkthroughs, and they all end up the same. So for sake of argument, I'm going to follow this one:
http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/
On the local machine I open a git bash and type:
ssh kannkor#1.1.1.1
It asks me for my password, I type it in.
I do the following (following the walkthrough).
d:
cd repos
I'm now at:
D:\repos>
Maybe this is where I've went wrong, by changing the drive/directory... But it must be possible.. continuing with the walkthrough
mkdir my_project.git
cd my_project.git
git init --bare
-> Initialized empty Git repository in D:/repos/my_project.git/
I did the git update-server-info (I've tried it with, and without, and had no impact on the final error).
On RDC, I can see it created the folder my_project.git and it has a few files/folders, hooks, info, objects etc. Not touching it, just noting it.
Onto the local machine
I type exit, to exit the ssh
Like previous, I want these saved on the d drive. To avoid confusion, I'm going to call the parent directory repositories.
I'm currently in: /d/repositories
mkdir my_project
cd my_project
git init
-> Initialized empty Git repository in D:/repositories/my_project/.git/
(changed git add * to git add --all)
git add --all
git commit -m "my initial commit message"
>On branch master
Initial commit
nothing to commit
git remote add origin kannkor#1.1.1.1:d/repos/my_project.git
git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'kannkor#1.1.1.1:d/repos/my_project.git'
I believe this is because the initial commit didn't have anything.
Still on the local machine, I navigate to: d:\repositories\my_project\
I create a file: placeholder.txt, and add a single line of text, then save it.
Back to git bash
git add --all
git commit -m "my initial commit message"
[master (root-commit) ac54490] my initial commit message
1 file changed, 1 insertion(+)
create mode 100644 placeholder.txt
Much better for the local commit. I try the push again.
git push -u origin master
kannkor#1.1.1.1's password:
fatal: ''d/repos/my_project.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.
This is about where I have gotten stuck. My assumption, is this line:
git remote add origin kannkor#1.1.1.1:d/repos/my_project.git
I've tried many various ways, including:
git remote add origin kannkor#1.1.1.1:d:/repos/my_project.git
With \ instead of /. Adding slashing to the end of it.
Few more various ones I attempted that all failed.
fatal: ''D:\repos\my_project.git'' does not appear to be a git repository
fatal: ''D:/repos/my_project.git'' does not appear to be a git repository
I also tried this, using the scp:
https://stackoverflow.com/a/20987150
Which ended in the same results.
Any advice would be appreciated.
d/repos/my_project.git does not look like a valid path.
/d/repos/my_project.git would.
Try:
git remote set-url origin kannkor#1.1.1.1:/d/repos/my_project.git
git push -u origin master
A little preliminary, but I do believe I have the answer/solution(work around).
https://github.com/PowerShell/Win32-OpenSSH/wiki/Setting-up-a-Git-server-on-Windows-using-Git-for-Windows-and-Win32_OpenSSH
In short, there is a known bug (been around since 2017), where when the default shell of the server is using cmd.exe, it is not consuming the single quotes. That's why the errors would come back with odd looking double single quotes.
fatal: ''D:\repos\my_project.git'' does not appear to be a git repository
The work around, is to change the default shell of the server, from cmd.exe to powershell. Details on doing this can be found here.
I'm copy/pasting the link above incase that link ever goes dead.
Before configuring DefaultShell, ensure the following prerequisites
are met
OpenSSH installation path is in system PATH. If not already present,
amend system PATH and restart sshd service.
Follow these steps:
On the server side, configure the default ssh shell in the windows
registry.
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSH\DefaultShell -
full path of the shell executable
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSH\DefaultShellCommandOption
(optional) - switch that the configured default shell requires to
execute a command, immediately exit and return to the calling process.
By default this is -c.
Powershell cmdlets to set powershell bash as default shell
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShellCommandOption -Value "/c" -PropertyType String -Force
To confirm you've done the above correct, when you ssh into the server, you should be in a powershell, instead of a cmd prompt.
And finally, the correct syntax for the commands, was indeed this:
kannkor#1.1.1.1:D:/repos/my_project.git
To kind of put it all together..
git remote add origin kannkor#1.1.1.1:D:/repos/my_project.git
git push origin master
kannkor#1.1.1.1's password:
Everything up-to-date

How do I use go get with a private github enterprise server?

We use github enterprise server over a VPN.
If I type:
go get privateserver.com/path/to/myproject.git
I get this result:
package privateserver.com/path/to/myproject.git: cannot download, privateserver.com/path/to/myproject uses insecure protocol
Or removing the .git suffix I get:
package privateserver.com/path/to/myproject: unrecognized import path "privateserver.com/path/to/myproject" (parse https://privateserver.com/path/to/myproject?go-get=1: no go-import meta tags ())
It seems there are many similar questions on google searches but have found no answers that actually work.
What I really want to end up with is automation of docker builds.
Inside my docker file I require a go get. But I can't store the credentials inside the docker file.
Note: --insecure doesn't work. See bottom of question.
Just tried go get with -insecure -v options.
I get the following output:
matthewh#xen:~/go/src/$ go get -insecure -v privateserver.com/path/to/myproject.git
# cd .; git ls-remote git://privateserver.com/path/to/myproject
fatal: remote error:
GitHub private mode is enabled. Git protocol is disabled. Use authenticated http or ssh access instead.
# cd .; git ls-remote https://privateserver.com/path/to/myproject
fatal: could not read Username for 'https://privateserver.com': terminal prompts disabled
# cd .; git ls-remote http://privateserver.com/path/to/myproject
fatal: could not read Username for 'https://privateserver.com': terminal prompts disabled
# cd .; git ls-remote git+ssh://privateserver.com/path/to/myproject
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
# cd .; git ls-remote ssh://privateserver.com/path/to/myproject
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
privateserver.com/path/to/myproject.git (download)
# cd .; git clone privateserver.com/path/to/myproject /home/matthewh/go/src/privateserver.com/path/to/myproject.git
fatal: repository 'privateserver.com/path/to/myproject' does not exist
package privateserver.com/path/to/myproject.git: exit status 128
The get command supports using http by using the -insecure flag as shown below:
go get -insecure privateserver.com/path/to/myproject.git
The default is secure HTTPS in order to prevent man in the middle attacks as described in Git Issue.

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.

Resources