Access private stash repo during npm install on Jenkins Access private stash repo during npm install on Jenkins jenkins jenkins

Access private stash repo during npm install on Jenkins


I solved this problem generating a ssh key from jenkins user.First I connect via ssh on jenkins host.

Then I generate a ssh private and public key using a jenkins user, not current or root user.I will give a bitbucket example:

su - jenkinsssh-keygen -f ~/.ssh/bitbucket -C "bitbucket"

Then you should create a config file to use this ssh key on every bitbuket request.

touch ~/.ssh/configchmod 755 ~/.ssh/configecho "# Bitbucket configuration" > ~/.ssh/configecho "Host bitbucket.org" >> ~/.ssh/configecho "   HostName bitbucket.org">> ~/.ssh/configecho "   IdentityFile ~/.ssh/bitbucket">> ~/.ssh/config

Lastly update ssh configs adding bitbucket private key:

ssh-add ~/.ssh/bitbucket

You can check if everythig is OK, checking by following command ssh-add -l and a line with private key configurations should be returned.


It's been two years since this question was asked, but it pretty accurately described the situation I was in as well, so I'll explain how I managed to resolve this in case someone else also finds themselves in the same situation.

Basically, you don't need to add the credentials to the build in jenkins in this situation. If id_rsa is present in that location and has the right permissions, git will actually pick it up automatically.

However, the reason it was hanging (for me anyway) was that it was asking whether to add the ssh fingerprint to the known_hosts file. For some reason, jenkins does not show this question and as the server is waiting for input, it just seems to be hanging.

The way to solve this is to create (/add the server to) ~/.ssh/known_hosts yourself. The easiest way to do is to run ssh <my git server> from the jenkins server by hand. It will then ask about the fingerprint and this time you can say yes. Once this is done, it won't ask again and the build should no longer hang.