Local Jenkins can't authenticate remote Gitlab private repository

13,298

Solution 1

My Fix :

  1. Go to jenkins path and save .ssh folder in root example C:\Jenkins.ssh .ssh folder u can find in C:\Users\yourname.ssh
  2. Go to Jenkins > Manage Jenkins > Manage Credentials, here you can add your private key or select from the jenkins master !/.ssh
  3. Go to Jenkins > Manage Jenkins > Configure System in git executable wrote this C:\Program Files (x86)\Git\cmd\git.exe path must be with cmd
  4. Create new job and in repository url add ssh://[email protected]:/name/projet.git

Solution 2

I have folder with .ssh with all keys

Those keys won't never been read, if you keep using an http(s) url.

You should use an ssh url, and first make sure that this works properly:

ssh -Tv ssh://git@git.*****.org

(assuming the user account you need on the server side is 'git')


Note that the section on SSH of this guide is of interest here:

you have installed TortoiseGIT

http://guides.beanstalkapp.com/version-control/git-on-windows/git-ssh-variable.png

If you have ever installed TortoiseGit on the computer you’re setting up your keys on, you may encounter problems.
TortiseGit creates an environment variable that configures Plink as your SSH keystore, which may conflict when you try to use Git and SSH.
No matter how you change your config or uninstall TortoiseGit, that environment variable persists and until you delete it, Git will not look to your regular .ssh directory to find the proper key.

In our case environment variable looked like this:

GIT_SSH=c:\Program Files\Putty\plink.exe. 

Environment variables can be found here:

  • Windows XP: Control Panel → System Properties → Advanced → Environment variables
  • Windows 7: Control Panel → System → Advanced system settings → Environment variables

Solution 3

Try using C:\Program Files (x86)\Git\cmd\gitk.cmd instead of \bin\git.exe. If not solved, then Here is information how to configure ssh. Sometimes you may also get public key error, which is solved here. If you want to generate new ssh keys, this article will help you.

Share:
13,298
Andrian Durlestean
Author by

Andrian Durlestean

Knowing: .net java python selenium sql javascript jquery

Updated on June 19, 2022

Comments

  • Andrian Durlestean
    Andrian Durlestean almost 2 years

    I installed Jenkins on windows with all addons that I need, I think so. When i create a new job and in Repository URL i write my url

    http://git.*****.org/*****/seleniumproject.git

    and it shows

    Help for feature: Repository URL
    Failed to connect to repository : Command "C:\Program Files (x86)\Git\bin\git.exe ls-remote -h http://git.*****.org/*****/seleniumproject.git HEAD" returned status code 128:
    stdout:
    stderr: fatal: Authentication failed for 'http://git.*****.org/*****/seleniumproject.git'`
    

    My question: how can I authenticate to my remote gitlab?! I have folder with .ssh with all keys but don't know what to do...

    Update: strange because my TortoiseGit is working perfectly

    My Fix :

    1. Go to jenkins path and save .ssh folder in root example C:\Jenkins\.ssh .ssh folder u can find in C:\Users\yourname\.ssh
    2. Go to Jenkins > Manage Jenkins > Manage Credentials, here you can add your private key or select from the jenkins master !/.ssh
    3. Go to Jenkins > Manage Jenkins > Configure System in git executable wrote this C:\Program Files (x86)\Git\cmd\git.exe path must be with cmd
    4. Create new job and in repository url add ssh://[email protected]:/name/projet.git
  • Andrian Durlestean
    Andrian Durlestean over 10 years
    Jenkins is sending url always with C:\Program Files (x86)\Git\bin\git.exe ls-remote so i can't use -Tv because of this ls-remote
  • VonC
    VonC over 10 years
    @AndrianDurlestean the -Tv is just for you to test ssh with the ssh -Tv. But once this is working, you don't need -Tv in your ls-remote.
  • Andrian Durlestean
    Andrian Durlestean over 10 years
    i get: no address associated with name
  • Andrian Durlestean
    Andrian Durlestean over 10 years
    ssh://git@git.****.org:9999/ my connection is with port =( i saw in my tortoisegit
  • VonC
    VonC over 10 years
    Can you try: ssh -Tv git@git.****.org:9999 (no ssh:// and no final /)?
  • Andrian Durlestean
    Andrian Durlestean over 10 years
    sad same problem =(, if Im trying with no port i get msg port 22: Bad file number, but my git server is with port 9999
  • VonC
    VonC over 10 years
    @AndrianDurlestean I have edited my answer to address git in an environment where TortoiseGit was already there.
  • VonC
    VonC over 10 years
    Excellent feedback. +1. More accurate than my answer
  • while1pass
    while1pass almost 7 years
    Hello, I have 2 questions. What is C:\Jenkins? Home dir for Jenkins? What do you mean in C:\Program Files (x86)\Git\cmd\git.exe path must be with cmd? Where can I set it?