Docker – How to get a public ssh key on a docker jenkins image for git authentication

dockerJenkinsssh-keys

I'm using Docker and I'm running a Jenkins image.
The image I'm trying: https://github.com/orchardup/docker-jenkins

I need to generate an ssh key pair so I may use it to authenticate to bitbucket. This is so that jenkins may pull my source code and build it.
Normally I would just su to the jenkins user and run ssh-keygen to achieve this.

I've edited the run file:

su jenkins

This gives me access to the shell where I may run ssh-keygen to install ssh keys into jenkins user home directory under ~/.ssh. After this I exit and the Dockerfile continues.
This home directory is /var/lib/jenkins which is also mounted as a volume on the host server.

Problem is that the ssh keys appear here but they are not working.
Any ideas how to achieve this in better way ?

Thanks

Best Answer

I just realised you are using git from the question, which I had managed to overlook...

Starting from version 2.0 of "Git Plugin" the credentials for specific repositories can be added in the "Source Code Management" section of the test itself. There should be a label called "Credentials" which allow you to use either a username/password or username/private key combination.

If you create a deploy key for each repository you're interested in running tests add this deploy key as the private key in credentials and you should be good to go.

Related Topic