In order for Jenkins to be able to have access to multiple repositories on the same server, I set the .ssh/config
as follow:
Host a.github.com
HostName github.com
User git
IdentityFile ~/.ssh/project-a-id_rsa
# same for other repos
and set the Jenkins jobs' Source Code Management (SCM), to git
and git@a.github.com:user/repo_a.git
. It works fine.
Problem
I want those jobs to be triggered on push events so I set a webhook service in github, .i.e, Jenkins (GitHub plugin). The request received from the webhook are "POST for https://github.com/user/repo_a" which is a different host than the one set in the SCM, .i.e, a.github.com
.
Because they are different, the job does not build automatically.
Ugly Solution
I got something running by setting the SCM to github.com
and override the remote url of the project's git config once cloned with a.github.com
. So the SCM would match the webhook, and jenkins when running git push
would use the .ssh/config
info.
Question
What else can I do ? Is there a better, easily automated way to achieve this?