Thursday, August 29, 2013

Configuring ssh for Jenkins for Git on Ubuntu

I ran into some problems configuring ssh for my jenkins box. It turns out that when installing jenkins on ubuntu via the package manager that jenkins is setup to run as its own user. So, Jenkins did not have access to my .ssh directory. Of course this made perfect sense once I stopped and thought about it.

Anyhow, I could not find a clear answer in one place so posted here. This assumes that you have an ssh key defined for your Git service of choice. I used the same key for myself and my Jenkins user. You can of course create your own ssh key for the Jenkins User.

1. Setup the Git settings for the Jenkins account - assume the identity of the Jenkins user and configure:

sudo su jenkins
jenkins@lubuntu:~$ git config --global user.email "some email address"
jenkins@lubuntu:~$ git config --global user.name "some name you associate with jenkins"
exit

2. cd to your user home directory and copy the .ssh key info into the Jenkins account.

cd /home//ssh
sudo cp id_rsa /var/lib/jenkins/.ssh/
sudo cp id_rsa.pub /var/lib/jenkins/.ssh/
sudo jenkins:nogroup chown /var/lib/jenkins/.ssh/id_rsa
sudo jenkins:nogroup chown /var/lib/jenkins/.ssh/id_rsa.pub

3. Assume the identity of Jenkins again, cd to the Jenkins directory, create a temporary directory, clone your repository from the Git repository, fix any issues this reveals then delete the temporary directory:

sudo su jenkins
cd /var/lib/jenkins
mkdir junk
cd junk
git clone git clone git@bitbucket.org:butbucket user name/user’s repository.git
cd ..
rm rf junk

4. Kick off your Jenkins build and verify that the Source Code Management plugin works.

No comments: