Let's remove jenkins from the picture to verify gitlab is setup correctly. I want to verify that if you were to use jenkins' key, you can clone the repo.
Steps:
- remove jenkins' deploy key from gitlab(save it)
- on your local machine, setup your ssh config file to have the git user use jenkins' key. this is a good link for config setup. (or better yet move your public and private key somewhere else and replace it with jenkins')
- verify that you cannot clone the repo using jenkins' key (#1 removed this access)
- add back jenkins' deploy key to gitlab
- verify that you can clone the repo.
There are several ways to have jenkins setup to clone repo using ssh. I'll describe what I do:
My jenkins instance runs on a different machine under the "tomcat7" user(this may be different for you). tomcat7's home directory on my box is /user/share/tomcat7
place jenkins' public and private keys in: /usr/share/tomat7/.ssh/
permissions do matter. use 600 for the private key and 644 for public key.
In the jenkins UI for a job..
When setting up the git section, copy-and-paste the ssh url from gitlab and explicitly set the credentials to none.
It's worth noting that our jenkins is a gitlab user(not using deploy keys), since our jenkins does pushes too.
Hopefully I didn't leave out any steps and this works for you!