Reputation: 918
I have a Jenkins instance and I am trying to create a continuous integration workflow. I am struggling to get jenkins to get the code onto the production server.
Here is what I'm trying to do:
I seem to be having the following problem:
deploy
.deploy
has id_rsa
keys in ~/.ssh
, with the contents of id_rsa.pub
in bitbucket's 'deployment keys' setting for the repo, I get a Permission denied (publickey).
error when I run git pull
or git clone
.So this has left me confused and I'm not sure where I'm going wrong.. For me it could be one or many of these things:
Any ideas, advice or alternative routes are greatly appreciated.
UPDATE
When running this myself as the same user that jenkins uses, when I run git clone ...
, I get prompted for the passphrase for id_rsa. This must be where jenkins is tripping up as it cannot decode id_rsa. I will see if I can generate an ssh key that doesnt prompt for a passphrase
UPDATE 2
I generated an ssh key for the production server that did not require a passphrase to use, and this worked fine.
Upvotes: 1
Views: 8920
Reputation: 918
The specific problem here was that the SSH key that I had made on the production server required a passphrase to use. The jenkins script couldn't handle this, so it sent the git pull
request with an encoded key so it got rejected.
I created SSH keys that required no passphrase and this solved my problem. This is the command I used:
ssh-keygen -t rsa -C "[email protected]" -N ''
The -N
flag sets a passphrase on the key.
Upvotes: 0
Reputation: 410
You should be using the Jenkins Publish over SSH plugin to talk to the target server from your Jenkins job. You can use it to run commands or scripts on the target. The SSH public/private key trust needs to be configured beforehand and configured in the plugin for the target server.
Upvotes: 0
Reputation: 1444
First of all, you should ensure git clone/pull works as intended on production server when launched manually.
Next, debug why doesn't it works driven by Jenkins.
Most likely reasons comes to my mind are:
I had implemented similar logic myself.
In my case production server was configured as Jenkins node, required HOME environment created in job workspace each time, and SSH and git access credentials are configured on Jenkins and populated on production on each run
PS: Using dedicated credentials for production server is absolutely normal (e.g. for security reasons)
Upvotes: 3