Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins on Openshift cannot clone repo

I'm new to both Jenkins and Openshift so getting tied up a bit.

I have set up Jenkins and pointed it to my github repo, but it can't clone it because I can't find anywhere to store my git credentials, and when I ssh into the jenkins box i can't access ~/.ssh to create new keys or find the ones in there. A further problem may also be that my git repo is private.

I've tried google but there's nothing that I could find. How do I allow Jenkins access my private git repo?

edit: ok i found in manage, then configuration a place for the username and email. then i have ssh'd in, and used ssh-keygen to create the ssh key in .openshift_ssh and added this to github, first as a normal ssh key, then as a deploy key, and then the same in app-root/data/.ssh but still nothing

like image 833
alsandair Avatar asked May 10 '16 21:05

alsandair


1 Answers

You can try and follow "Building a project hosted on Github using an Openshift Jenkins instance " from Ramzi Maâlej.

Make sure Openshift doesn't grant write permission on several folders on a Jenkins instance such as: .ssh, .m2. (or ssh would not work anyway, because of right on folders "too permissive")
That alone could be the source of your problems, but if that is not enough, read on.

Then:

rhc ssh buildserver
mkdir app-root/data/git-ssh
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f $OPENSHIFT_DATA_DIR/git-ssh/id_rsa

Deploy your $OPENSHIFT_DATA_DIR/git-ssh/id_rsa.pub to your GitHub account

Create a script ssh-wrapper.sh that does the following:

#!/bin/bash

ID_RSA="$OPENSHIFT_DATA_DIR/git-ssh/id_rsa"
KNOWN_HOSTS="$OPENSHIFT_DATA_DIR/git-ssh/known_hosts"

ssh -o UserKnownHostsFile=$KNOWN_HOSTS -i $ID_RSA $1 $2

Don't forget to make it executable: chmod +x ssh-wrapper.sh

Test it:

 ./ssh-wrapper.sh -T [email protected]
Hi Jenkins! You've successfully authenticated, but GitHub does not provide shell access.

Finally, configure Jenkins:

go to Manage Jenkins > Configure System > Global Properties and create a new environment variable called GIT_SSH that refers to the location where you created your wrapper.

like image 162
VonC Avatar answered Sep 30 '22 20:09

VonC