Jenkins on openshift #3 – building repo from github or bitbucket
Posted: December 16, 2013 Filed under: java, Linux, Mac, programing | Tags: bitbucket, git, github, jenkins, openshift, SonarQube, ssh Leave a commentNext task I wanted to do is to create jenkins on openshift and be able to build projects from github or bitbucket. It sounds simple, but you will face quite a lot of issues. So let’s do it:
Create Jenkins gear
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rhc create-app jenkins jenkins-1 "https://cartreflect-claytondev.rhcloud.com/reflect?github=majecek/openshift-community-git-ssh" |
- this creates gear called “jenkins” using jenkins-1 application and includes ssh wrapper “git-ssh” which helps you to overcome ssh obstacles (openshift forbids to write into .ssh folder) – as you will see we will have to solve this problem several times later as well
Set jenkins slave
jenkins needs other linux machines (called slaves) to use them for building, anyway we don’t have so much free gears, so we will use jenkins itself for it.
Manage Jenkins -> Configure System -> # of executors = 1 Labels = put here anything
Generate ssh key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd app-root/data/git-ssh/ | |
ssh-keygen (name your key as id_rsa – git-ssh will look there for it) | |
and set full path for new key (i.e. /var/lib/openshift/52ab37d0500446f3d30000ee/app-root/data/git-ssh/id_rsa) |
Add public key (id_rsa.pub) to github & bitbucket
search github/ bitbucket how to do it 🙂
Add new Jenkins Job
- in begining I mentioned that home folder is not writeable, so we are encountering several problems, like ssh can’t write into .ssh , maven can’t write into .m2 folder and so on. The only solution is to point all applications into writeable folder which is $OPENSHIFT_DATA_DIR
- Because of the problem above, you can’t use standard maven jobs but you have to use “Build a free-style software project”
- Source Code Management: git: your git url (i.e. git@bitbucket.org:majecek/testtest.git)
- Build: (add Execute shell): enter:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd $OPENSHIFT_DATA_DIR | |
echo -e "<settings><localRepository>$OPENSHIFT_DATA_DIR/.m2</localRepository></settings>" > settings.xml | |
cd $WORKSPACE | |
mvn clean compile test package -s $OPENSHIFT_DATA_DIR/settings.xml |
- this creates setings.xml file and when runing maven commands – you have to specify where is the settings file
- check this site for more info
- next step is to add hooks in github/bitbucket – so after push in repo they will trigger jenkins to create new build – again check it in github/bitbucke or this site
Feed Sonar with data from Jenkins
This was quite a problem. I have to admit that I didn’t finish it, but found solution. Here is another problem, sonar and specially it’s mysql runs on different gear and openshift by default don’t allow any connection between gears nor from outside.
- install Sonar plugin into jenkins, add URL & jdbc url and all info needed
- I had to add into Sonar Aditional properties: -DSONAR_USER_HOME=$OPENSHIFT_DATA_DIR
- this is again, because sonar can’t write into home directory, so you have to point to writeable folder
Now you will face problem, that jenkins can’t connect to MYSQL DB – as said above, this is because gears can’t communicate to each other. There are 2 solutions:
- set up SONAR as scaled application – scalled applications can communicate to each other
- setup ssh port forwarding between applications
You can read more here.
How to run SonarQube 4.0 on openshift
Posted: December 6, 2013 Filed under: Linux, Mac, programing | Tags: git, openshift, redhat, sonar, SonarQube 4 CommentsI have managed to run latest SonarQube on openshift for free.
Because openshift has bug you can’t just have one-line command to do all setup for you, but I had to separate it into several commands and two git repos.
Bug
you can’t have .openshift folder in repo – so I have to have 2 git repos
- git repo with sonar without (.openshift folder)
- git repo with .openshift folder with start & stop commands
How to get SonarQube 4.0 running on openshift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rhc create-app sonar diy-0.1 mysql-5.1 –from-code https://bitbucket.org/majecek/sonarqube-openshift.git | |
cd sonar | |
git remote add upstream -m master https://bitbucket.org/majecek/sonarqube-openshift_addons.git | |
git pull upstream master | |
git pull origin master | |
git push origin master |
Description
- when RedHat fixes the bug, you should be fine, just with line #1
- cd into project
- add another git repo which holds .openshift folder with start & stop commands
- get changes from repo above
- pull from origin repo – git was complaining when I didn’t do pull
- push into openshift
- wait several minutes until sonar gets running
Thanks
Big thanks goes to Rui Rodrigues(@rodriguesrmb) as he managed to solve port binding problems and update java wrapper with new version