short version
I'm using aliasing to connect my remote Git repositories. It works, but when I add such repository to Jenkins, it cannot access the repository and display the error:
Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h git@github.com-foo:myaccount/myrepository.git HEAD" returned status code 128: stdout: stderr: ssh: Could not resolve hostname github.com-foo: Name or service not known fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
detailed issue description
In order to commit
/push
code as different users I use aliasing:
C:\Users\myusername\.ssh\config
...
#github.com-foo account
Host github.com-foo
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_foo
#github.com-bar account
Host github.com-bar
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_bar
...
Then instead of
git clone git@github.com:myaccount/myrepository.git
I simply use
git clone git@github.com-foo:myaccount/myrepository.git
The .ssh
directory is accessible from my local VMs as a shared folder, so also use my credentials on the VMs as well.
Everything works.
Now I installed Jenkins on a VM and want to configure the connection to a remote repository stored on GitHub. What I did:
Credentials:
Jenkins -> Credentials -> [link] Global credentials (unrestricted) -> [radio button] Enter directly -> [textarea] Key -> added -> [button] Save
.Git plugin:
Jenkins -> Configuration -> [section] Git plugin
-- Email and Name set up:
- Project Git settings:
[project] -> Configuration -> [section] Source Code Management -> [section] Git
-- Repository URL and credentials:
As on the screenshot shown, the connection is failing.
Why does it not work and how to get it working, in order to connect a remote Git repository in Jenkins using aliases?