Jenkins: Failed to connect to repository

后端 未结 13 1652
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 04:16

I\'m trying to connect jenkins on a github repo.

When I specify the Repo URL jenkins return the following error message:

Failed to connect to

13条回答
  •  暖寄归人
    2020-12-03 05:09

    I faced a similar issue when I tried to connect jenkins in my Windows server with my private GIT repo. Following is the error returned in the source code management section of Jenkins job

    Failed to connect to repository : Command "git.exe ls-remote -h ssh://git@my_server/repo.git HEAD" returned status code 128: stdout: stderr: Load key "C:\Windows\TEMP\ssh4813927591749610777.key": invalid format git@my_server: Permission denied (publickey). fatal: Could not read from remote repository.

    Please make sure you have the correct access rights and the repository exists.

    This error is thrown because jenkins is not able to pick the private ssh key from its user directory. I solved this in the following manner

    Step 1

    In the jenkins job, fill up the following info under Source Code Management

    Repositories

    Repository URL: ssh://git@my_server/repo.git
    Credentials: -none-

    Step 2

    In my setup jenkins is running under local system account, so the user directory is C:\Windows\System32\config\systemprofile (This is the important thing in this setup that is not very obvious).

    Now create ssh private and public keys using ssh-keygen -t rsa -C "key label" via git bash shell. The ssh private and public keys go under .ssh directory of your logged in user directory. Just copy the .ssh folder and paste it under C:\Windows\System32\config\systemprofile

    Step 3

    Add your public key to your GIT server account. Run the jenkins job and now you should be able to connect to the GIT account via ssh from jenkins.

提交回复
热议问题