Working with Jenkins Docker
A few days back, our QA guys needed some help. They were unable to pull the code from our private Git repo through their JENKINS server, and asked me if I could help them.
Now, previously when I had worked on Jenkins, we had svn as our repository. One good thing about the repo is, it is URL based and a lot many permissions problems that we face with Git is not there (we had to access our code over VPN then).
A lot of search over the internet, couldn’t help and I had to connect a few dots to solve our problem at hand.
Why dockers?
I have become a big fan of dockers, owing to the ease of operations and the simplicity they have. And hence even when the QA guys asked me to debug it on their server, I preferred to pull a docker onto my Mac and work on it.
Let me guide through this (I expect you have docker process running on your machine, and your repo uses ssh keys to verify access to Git server).
Step 1: Getting the JENKINS docker.
docker pull jenkins
docker run -p 8080:8080 -p 50000:50000 -v \ /your/home:/var/jenkins_home jenkinsPlease note, the -v option is quite important, because we would store generated .ssh keys there. Now, we need to login to the docker to generate keys.
docker exec -ti jenkins bash(Inside the docker now, verify you are "jenkins" user.)ssh-keygen(please don't use an empty passphrase, and don't rename the generated key files).cd ~/.sshpwdexit
Now, copy the key files (id_rsa and id_rsa.pub).
docker cp jenkins:<path of .ssh>/id_rsa.pub .
docker cp jenkins:<path of .ssh>/id_rsa .Copy these two files, into the <path where you mounted volume>/.sshAnd add the public key to the git repo.
Now, on your MAC create a new user “jenkins”.
After the jenkins user is created, move into your mounted volume. The below steps are totally important.
- Move to the mounted volume, and navigate to .ssh directory. Change permissions first
chmod 644 *and also the ownershipchown jenkins:jenkins * - Similar changes need to be made to the .ssh directory too
chmod 700 .sshandchown jenkins:jenkins .ssh
Step 2: Setting up the project
Restart the jenkins docker, and open the URL http://localhost:8080 on your browser, create a project of type “Free Style Project” (the simplest one).
While creating a new job, you would be asked to enter the SCM details like the url for Git repo. The format should be ssh -vT <your git url> and for the credentials, you need to modify the existing “jenkins” credentials with username as “jenkins” and the private key as “From the Jenkins master ~/.ssh”
That should be all, and you can now go ahead with building your project.
This post was more about handling the permission issues that you might face while cloning your repo. Will come up with more as I explore deeper.

