I've created a node package that I'd like to use in my company's primary application. Both my package and the application are stored in private git repositories. Here is an the relevant portion of my package.json
file:
"dependencies": {
"qc-event-logger": "git+ssh://[email protected]/qc-event-logger.git#v1.0.0"
},
I'm able to run and build it locally, and everything works fine. The problem is when I try to deploy from our Jenkins build server. The npm install
build task hangs. It doesn't fail or throw an exception, it just sits on that step until I kill the build agent.
I can't be sure, but I think it's failing because it isn't providing an ssh key for the node package. I tried adding an SSH key credential:
But that appears to only be related to pulling the whole project down, and I can't find any way to attach the credentials to a build task. I tried switching the credentials for the main application's git repo to SSH, but it's not set up that way.
Is there a way to either:
a) attach an SSH key to a Jenkins build task, or
b) specify the SSH key at the command line, either before calling npm install
or as a parameter?
Step 1: go to your GitHub repository and click on 'Settings'. Step 2: Click on Webhooks and then click on 'Add webhook'. Step 3: In the 'Payload URL' field, paste your Jenkins environment URL. At the end of this URL add /github-webhook/.
Configuring Git with Jenkins Now open your project and go to configure. Step 2: Give the repository Url in Source Code Management, repository Url can be fetched by clicking on clone and download option of Github and you have to select the SSH Url. Also, add credentials there of 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 - jenkins
ssh-keygen -f ~/.ssh/bitbucket -C "bitbucket"
Then you should create a config file to use this ssh key on every bitbuket request.
touch ~/.ssh/config
chmod 755 ~/.ssh/config
echo "# Bitbucket configuration" > ~/.ssh/config
echo "Host bitbucket.org" >> ~/.ssh/config
echo " HostName bitbucket.org">> ~/.ssh/config
echo " 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With