6

I am trying to create a Maven project in Jenkins. The code is in Git repository which uses non standard port 1754.

The port details are already there in the config file but the git plugin in jenkins is not able to connect. It is giving error for port 22.

Following error is coming in Jenkins (Git section) after adding following url: gitolite@10.115.2.110:AutomationCode

  Failed to connect to repository : Command "/usr/bin/git -c 
  core.askpass=true ls-remote -h gitolite@10.115.2.110:AutomationCode 
  HEAD" returned status code 128:
  stdout: 
  stderr: ssh: connect to host 10.115.2.110 port 22: Connection refused 
  fatal: Could not read from remote repository.
  Please make sure you have the correct access rights
  and the repository exists.

When I cloned the git repository directly from terminal it is working fine but in Jenkins it is not using the config file for port.

I tried giving ssh URL but it is also not working. "Connection refused" error is coming. I tried giving fixed port number in Manage Jenkins -> configure system page in SSH Server section. But still issue is unresolved.

Is there any way by which we can configure a project to use specific port in Jenkins -> Git or maybe access the .ssh/config file to take the port number ?

I am using SSH Keys to access the git.

Dharmesh Porwal
  • 1,406
  • 2
  • 12
  • 21
Shashank
  • 350
  • 3
  • 15
  • What url are you using when you are cloning from the command line? – VonC Jan 16 '15 at 07:37
  • git clone gitolite@10.115.2.110:AutomationCode There is no place to specify port in this. So I created config file in .ssh folder to specify port 1754. This worked in command line. But in Jenkins it is picking up port 22 only. – Shashank Jan 16 '15 at 07:41
  • As I thougt: hence my answer below. – VonC Jan 16 '15 at 07:41

2 Answers2

1

If you are cloning from the command line using the same url (gitolite@10.115.2.110:AutomationCode), then:

  • you are using the port 22 (standard for ssh), or as noted below, a ~/ssh/config file with an "Host gitolite" entry.
  • you might not be using the same ~/.ssh with Jenkins as you are in command line with your account.

Make your Jenkins jobs print 'env' to see if the environment variable (and username) are the same as the ones you would see in your terminal.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • with command line I am using config file in .ssh folder to specify port i.e 1754. – Shashank Jan 16 '15 at 07:50
  • @shashank do you have an "`Host gitolite`" in your config file? Anyway, your Jenkins must run under a different account, or it would access the same `~/.ssh/config` file as you do in command line. – VonC Jan 16 '15 at 07:54
  • I added the config file in /var/lib/jenkins/.ssh folder. Now that error is not coming. But a different error is coming related to permission issues: ** " stdout: stderr: Bad owner or permissions on /var/lib/jenkins/.ssh/config fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. " ** I tried changing the permissions of .ssh folder and config file but still same error. Also I tried running jenkins with root user to resolve permissions issue but still same error. – Shashank Jan 16 '15 at 10:08
0

Found https://serverfault.com/questions/218256/specify-ssh-port-for-git

Login with jenkins, switch to home dir(default is /var/lib/jenkins), set port in .ssh/config, and remove port from git@foo.com:[port]/git/bar.git from pipeline script, then git clone sucessfully. I think it tedious, but it works.

Note: you must have an ssh public key on the remote git server.

Community
  • 1
  • 1
XIA YUN
  • 23
  • 6