3

I'm having an issue right now trying to set up a Jenkins job (on one Windows server) to monitor an internal Git repo located on a Gitosis server (on a different Windows server).

The url looks like this: ssh://git@192.168.0.1:relative_path/repo.git (real values replaced for security, also the relative path will not work with a '~/', it only works without a leading '/').

When running git clone from the command line with the url, everything comes out fine.

When configuring a Git SCM in the Jenkins job it is able to run an ls-remote command (this confirms that the ssh keys are properly configured for the Jenkins instance).

However when the job executes, the url appears to be rewritten with an additional forward slash which causes the clone command to fail.

Started by user Meh
[EnvInject] - Loading node environment variables.
Building in workspace D:\local_repo_test
 > git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url ssh:///git@192.168.0.1:relative_path/repo.git # timeout=10
Fetching upstream changes from ssh:///git@192.168.0.1:relative_path/repo.git
 > git.exe --version # timeout=10
 > git.exe -c core.askpass=true fetch --tags --progress ssh:///git@192.168.0.1:relative_path/repo.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error fetching remote repo 'origin'
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

It's the '///' that bothers me. Has anyone seen anything like this?

Any help on this would be appreciated.

timmyonline
  • 193
  • 13

6 Answers6

2

As far as I can tell from checking various versions of git, the relative path syntax you're using with the ssh protocol is ambiguous. It is interpreted as you hope on msysgit versions on Windows, but not on any other platform which I tested.

When I tested

  • git 1.7.1, CentOS 6.6, git clone ssh://mwaite@mark-pc1:bin/ fails and reports ssh: Could not resolve hostname mark-pc1:bin: Name or service not known
  • git 1.7.2.5, Debian 6, git clone ssh://mwaite@mark-pc1:bin/ fails and reports ssh: Could not resolve hostname mark-pc1:bin: Name or service not known
  • git 1.7.10.4, Debian 7, git clone ssh://mwaite@mark-pc1:bin/ fails and reports ssh: Could not resolve hostname mark-pc1:bin: Name or service not known
  • git 2.1.4, Debian Testing, git clone ssh://mwaite@mark-pc1:bin/ fails and reports fatal: '/' does not appear to be a git repository
  • git 2.2.1, Ubuntu 14.04, git clone ssh://mwaite@mark-pc1:bin/ fails and reports "fatal: '/' does not appear to be a git repository"
  • git 2.3.0, Ubuntu 14.04, git clone ssh://mwaite@mark-pc1:ssh/home/mwaite/bin succeeds and clones the repo from /home/mwaite/bin using ssh protocol

As far as I can tell, if the first word after the colon is a protocol (like ssh) or a port number (like 22), then that is interpreted as the service or port number to be used for repository access.

I further described some of those details in JENKINS-26680 and JENKINS-27483

Mark Waite
  • 1,351
  • 11
  • 13
1

Since I couldn't make any traction with the Jenkins people on trying to address why the url gets rewritten with '///' and I also couldn't determine if anything was wrong with Gitosis I figured out a work around.

Since Cygwin, SSH, and Gitosis were already installed and running I decided to add a new user to the machine and run all the git ssh command through it.

Followed the steps here to add a new user http://techtorials.me/cygwin/create-and-add-users/

Then I chmod'ed and chgrp'ed /home/git/reposotories to the sshUsers group. Once that was in place I was able to use a Git SSH url with an absolute path name bypassing the '///' url issue with jenkins.

timmyonline
  • 193
  • 13
1

I was experiencing the same problem using Jenkins in combination with a private bitbucket repository that I wanted to clone over ssh. As mentioned in the answer by Mark Waite, this is recognized by some as a bug. However, there are others that think this is expected behaviour because 'relative URIs' are not suported JENKINS-26327.

A temporary workaround that worked in my case was to add the port number 22. So in the Jenkins pipeline I replaced

url: 'ssh://git@bitbucket.org:/my_team/my_repo.git'

with

url: 'ssh://git@bitbucket.org:22/my_team/my_repo.git'

And now the pipeline runs as expected.

mrz
  • 55
  • 1
  • 9
0

This is a longshot, but just to check - are you maybe using parameters in the path? Something like $PROTOCOL/$URL/$PATH with PROTOCOL='ssh://'? Sounds far-fetched, so no offense meant. But I once did something similar and the parameterisation prevented me from seeing that the field was actually sending one slash more than it should.

Sir Jane
  • 232
  • 2
  • 12
0

This Worked For Me.

ssh://awc@192.168.1.32:22/home/awc/GIT_HOME/awc.git

i.e. by putting extra port number 22 (SSH Port) after the IP address

Pratik Gaurav
  • 661
  • 7
  • 8
0

While using a Git SSH url with the prefix ssh://, replace the colon just before the organization name with a forward slash:

git clone ssh://git@192.168.0.1/relative_path/repo.git

Or simply use the URL as is without the prefix ssh://:

git clone git@192.168.0.1:relative_path/repo.git

Dibakar Aditya
  • 3,893
  • 1
  • 14
  • 25