Jenkins on openshift #3 – building repo from github or bitbucket

Next 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 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

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 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.

Advertisements

SonarQube part #2 – let’s feed it with some data

In previous article, I have showed you how to build sonarqube 4.0 on openshift¬†, but let’s feed it with some data.

  • Let’s create dummy j2ee project using maven
    • mvn archetype:generate
    • cd <<project_name>>
    • mvn clean compile
  • openshift port forward to access database
    • rhc port-forward <<APPLICATION_NAME>>
    • you should see something like this:
      Service      Local                            OpenShift
      ——- ————– ¬† ¬† ¬† —- ¬† ¬† —————
      java     127.0.0.1:8080 => 127.X.X.X:8080
      mysql 127.0.0.1:3306 => 127.X.X.X:3306
    • database can be accessed on localhost:3306

Now we have few options how to feed sonar

  • maven – best for maven projects
  • sonarqube runner – best for java legacy code
  • jenkins,….

Maven projects

5 things to change or consider:

  1. jdbc url –¬†make sure you have correct url, port, application name
  2. mysql username
  3. mysql password
  4. sonar host url
  5. I am using maven version 3 – in case you have maven version 2 you have set different dependences

to run:

mvn clean compile sonar:sonar 

or (including profile name to be used)

mvn clean compile sonar:sonar -Dsonar.profile="Sun checks"

SonarQube Runner

4 things to change or consider:

  1. jdbc url – make sure you have correct url, port, application name
  2. mysql username
  3. mysql password
  4. sonar host url

to run:

  • you have to download SonarQube runner & set PATH variable
    export SONAR_RUNNER_HOME=/Path/to/SonnarRunner/sonar-runner-2.3
    export PATH=$SONAR_RUNNER_HOME/bin:$PATH
  • create file called “sonar-project.properties” and fill it with info mentioned above in gist
  • run:
    sonar-runner

Now change code (i.e. add empty private method, named with upper case letter, ….) and run analysis again to feed sonar. Check sonar – it shows you all violations and issues in your code, … ¬†(also it depends on plugins you have installed on your sonar)

Example project can be found on Bitbucket


How to run SonarQube 4.0 on openshift

I 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

  1. git repo with sonar without (.openshift folder)
  2. git repo with .openshift folder  with start & stop commands

How to get SonarQube 4.0 running on openshift

Description

  1. when RedHat fixes the bug, you should be fine, just with line #1
  2. cd into project
  3. add another git repo which holds .openshift folder with start & stop commands
  4. get changes from repo above
  5. pull from origin repo – git was complaining when I didn’t do pull
  6. push into openshift
  7. 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


muCommander and external editor

If you want to use other editors/viewers with muCommander you have to do

  • find “preferences.xml” file (in Mac it ¬†“~/Library/Preferences/muCommander”) or check this page
  • Add this section:
  <editor>
     <use_custom>true</use_custom>
     <custom_command>open -a Sublime\ Text\ 2 $f</custom_command>
 </editor>
    • as you can see I am using “Sublime ¬†Text 2” text editor
    • don’t use ¬†quotation’s marks as it didn’t work
    • more can be found on this forum

 To note:

  • don’t use quotation marks – as mentioned above
  • use external editor to edit “preferences.xml” file
  • make sure mucommander is closed otherwise it likes to ¬†overwrite your changes
  • it it doesn’t work check whether you got your changes in that file (could be overwritten by muCommander)

Do you want TRIM on mac ?

Apple has started to support TRIM on OSX Lion. What was my¬†surprise¬† when I have find out that it works only on SSDs provided by Apple. Not sure why, but it seems it is apple’s way.

Anyway check TRIM Enabler – according description it should work even on snow leopard. I have tested it on Lion and it works.

 


GSL – GNU statistics library

If you need to do some calculation (like statistics, math, ….) check out the GSL library.

It has lots of method already written like standard derivation, correlation, mean, monte carlo analysis etc…

I have connected this library (which is written in C) to ruby.

steps:

  • download and install GSL (configure -> make -> make clean -> make install => see readme)
  • for ruby: ¬†gem install gsl ¬†(check ruby-gsl project for examples)
that’s it ūüôā

How to boot MBP without working DVDRom

I don’t use my DVDRom at all. After couple years I have found out that it is not working at all (of course it was jusst in situation where I needed).

I was in situation where I had to boot install DVD to repair my HD but how to do it when your DVDRom is not working? Here are few list what I have tried:

  • clean your DVDRom – yes it helps, probably there is just dust, but I hadn’t have my cleaning set around me
  • use “Remote install Mac OSX” – this tool works only for MacBook Air and Mac mini. MacBook Pro will not be able to boot using this tool, why ? ¬†(Apple what’s wrong with you)
  • boot from external HD – should be possible, but my external HD died ūüė¶
  • tried to use external DVDRom and connect it through USB – yes it is working

So good news is that Apple has not forbidden external dvdrom. This is the way I am using now to boot my MBP. I really would like to know why they prohibited to boot from network using “remote install mac osx”. Apple don’t be crappy !