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 [email protected]: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 [email protected]:myproject.git
ERROR: Cause: Error performing command: C:\Program Files (x86)\Git\cmd\git.cmd clone --progress -o origin [email protected]:myproject.git C:\Program Files (x86)\Jenkins\jobs\myproject\workspace
Command "C:\Program Files (x86)\Git\cmd\git.cmd clone --progress -o origin [email protected]: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?
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
before
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.
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:
HOME
HOME
to%USERPROFILE%
To display the variables, use the Parametrized build feature: