3

I'm having a hard time configuring Jenkins, running as a Windows Service, to connect to a git server (gitosis) and clone a repository. Jenkins is set to use the standard Git plugin.

Everything is hosted by us: the Jenkins server is on win.foo.com and gitosis is running on a linux server (git.foo.com).

If I RDP into win.foo.com I can clone (git.exe clone --progress -o origin git@git.foo.com:myproject.git myproject) from the command line without issue.

Jenkins is running as a service and because it's not running under the same user account I've copied the .ssh folder to %SystemRoot%\System32\config\systemprofile (as defined in the %USERPROFILE% environment variable) and C:\Program Files (x86)\Git\, but neither of these seem to be picked up by Jenkins, even after a full restart.

I've tried using both git.exe and git.cmd; no joy in either case.

Jenkins is failing with the following error message:

ERROR: Error cloning remote repo 'origin' : Could not clone git@git.foo.com:myproject.git
ERROR: Cause: Error performing command: C:\Program Files (x86)\Git\cmd\git.cmd clone --progress -o origin git@git.foo.com:myproject.git C:\Program Files (x86)\Jenkins\jobs\myproject\workspace
Command "C:\Program Files (x86)\Git\cmd\git.cmd clone --progress -o origin git@git.foo.com:myproject.git C:\Program Files (x86)\Jenkins\jobs\myproject\workspace" returned status code 128: Cloning into C:\Program Files (x86)\Jenkins\jobs\myproject\workspace...
Access denied
fatal: The remote end hung up unexpectedly

I'm sure I've missed something, but I'm not sure what.

Advice?

Phillip B Oldham
  • 1,016
  • 5
  • 15
  • 24

2 Answers2

4

I've been reading the following article, which is closely related: How do I tell Git for Windows where to find my private RSA key? and it gave a good hint: The HOME-Variable is crucial, but it didn't work out the way I thought.

After a lot of reasearch and trying I found this article: http://markashleybell.com/portable-git-windows-setting-home-environment-variable.html

In fact it is not enough to set the environment-variable in windows as usual, when running ssh from a service account, but change the configuration so the keys are actually found.

Short relevant outline:

Navigate to C:\Program Files\Git\etc\profile and add the following line

HOME="/c/Users/YourUserAccount"

before

# normalize HOME to unix path
HOME="$(cd "$HOME" ; pwd)"

This solved it for me, because now Git always uses your statically assigned path for home. Just make sure you don't get any security-issues with this approach with other users on this machine.

Alexander Pacha
  • 169
  • 2
  • 9
1

The only parameter you need to really check is the %HOME% environment variable value, when Jenkins tries to clone.
You need to display the 'set' (environments variable) of the Jenkins session and see if HOME has been defined, and if it has, to which path.

Reminder:

  • Windows, by default, doesn't define HOME
  • msysgit defaults HOME to %USERPROFILE%

To display the variables, use the Parametrized build feature:

Reference parameter by name in builder. I'm using the "env" command to show the variable, followed by an echo statement to demonstrate referencing the value:

command shell in parametrized Jenkins job

VonC
  • 2,653
  • 5
  • 29
  • 48
  • Any idea how I can view the `%HOME%` env variable through Jenkins? – Phillip B Oldham Aug 04 '11 at 08:15
  • @unpluggd: I have edited my answer to address your question. – VonC Aug 04 '11 at 08:34
  • Thanks! Doesn't show that `HOME` is set though; as you said, `HOME` isn't set by default. Is it possible to set this? – Phillip B Oldham Aug 04 '11 at 09:02
  • @unpluggd: on Windows, HOME isn't set, that means you have to set it either on the User Environment Variable side, or on the System Environment variable side as in http://www.howtogeek.com/51807/how-to-create-and-use-global-system-environment-variables/ – VonC Aug 04 '11 at 09:34
  • Still getting `access denied`! There's no `HOME` var even though Jenkins is now running as a new user. – Phillip B Oldham Aug 04 '11 at 11:28
  • @Philip: "There's no HOME var": that needs to be addressed. Did you define HOME as a system environment variable? – VonC Aug 04 '11 at 13:39
  • @VonC let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/991/discussion-between-phillip-oldham-and-vonc) – Phillip B Oldham Aug 04 '11 at 13:45