how to make CI tool hudson work for rails project on ubuntu

hudson is awesome CI(continuous integration) tool. 

We want to install it on our ubuntu server to do CI for our rails projects.

Here are the steps of how to make it work:

1. ssh username@servername, to login remotely to your ubutu server.

(After you install a brandly new ubuntu on the server, you will need to sudo apt-get install openssh-server, then you can ssh it from your laptop)

2. install hudson on the ubuntu server, here is the instructions:

(the good news after you finished the installing is, hudson is already so system daemon that will be auto-started when ubuntu reboot.)

(after installed hudson and reboot ubuntu server, open a web browser, access http://serveaddress:8080/, you can see the lovely interface of hudson. Then you need to install several plugins for hudson, like ruby, rake, git etc, this can be easily done through hudson UI)

3. install ruby on the ubuntu server, run the following command

sudo apt-get install ruby

(this will install ruby 1.8.7 as default)

4. after login ubuntu server on your laptop, run this command on the terminal of your laptop to act as the hudson user auto-created by the hudson installation.

sudo -Hiu hudson 

(you have to act as hudson user, because the next step is to install rvm, if you install rvm under another account, hudson account will not be able to execute rvm command.)

5. install rvm, here is the instructions:

(make sure you are using hudson account on ubuntu, by this way, the rvm will be installed under hudson directory)

(you will need to create a .bashrc file to $HOME dir, and add a this line to that file

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function)

5. rvm install ruby-1.9.2

6. rvm --default ruby-1.9.2


then we are almost there!


7. How to set Hudson to use to send emails after a build failed?

go to hudson config page

smtp server:

username: ******

password: *******

usessl, true

smtp port: 465

charset: utf-8



8. I run into another problem when trying to check out a project.

We used "externals" feature in svn 1.6, but when I build a project for the 1st time, the code in external is not checked out.

My solution is in the config screen of the project, at the section setting svn urls, press "add" to add a location.

then fill in the svn url of the external codes,

then fill in correct local directory that the external codes should go in.

then this problem is bypassed. 


9. set the build part in project:

a. select "execute shell"

b.  add the following lines:


# Environment setup

#source "$HOME/.rvm/scripts/rvm"

# Use the correct ruby

rvm use 1.9.2@gemsetname

# Do any setup
# e.g. possibly do 'rake db:migrate db:test:prepare' here
# bundle install
# Finally, run your tests
10. when using emai-ext plugin, the email content should be:
Check console output at $BUILD_URL to view the results.
Below is the raw output:
${BUILD_LOG, maxLines = 100000}

Posted by 张晓峰 01 Jul 2011 at 09:03AM

how to solve " cannot open shared object file" when using RVM in red hat

On linux server, we installed glpk library. then we installed rglpk gem under a gem set through RVM.

We try to use rglpk in our soft, but got this error: cannot open shared object file: No such file or directory -    

If we install the rglpk gem under system ruby paths, (by using sudo gem install rglpk), rglpk will work as expected.

From the error message, we deduce the problom is rglpk can't find the file.

Then we checked the usr/local/lib dir, we find that file is actually there, what's wrong?

readelf -a

Using this command to check the content in the binary file rglpk-0.2.4/lib/ and comparing this file the from system ruby, we find that library path is wrong in RVM's

In RMV's file, the library path is ruby/.rvm/gems/..../lib

In system file, the library path is usr/local/lib

So we make a link from RVM's library path to the correct library path usr/local/lib like this:

ln -s /usr/local/lib/

Finally, this solved the issue, and rglpk works again!

So the reason is when we run gem install rglpk under a specific gemset under rvm, the library path indicated in file is wrongly configured.

Posted by 张晓峰 22 Jun 2011 at 06:00AM

using rvm @global gemset

It’s cool to have different gemset for each project. However, the problem is that you have to install gems, e.g. thin, bundler, etc, that shared among them again and again.
Of course, there is already good way to deal with this:

RVM provides (>= 0.1.8) a @global gemset per interpreter.

Gems that are installed to the per-interpreter @global gemset are available to all other gemsets for that interpreter.

This is a good way to allow all of your projects to share the same installed gem for a specific ruby interpreter installation.

see for more details

Below shows an example about installing bundler into @global gemset:

$ rvm 1.9.2@global

$ gem install bundler —no-ri —no-rdoc
$ rvm use 1.9.2@other_gemset
$ gem list

You should see bundler in other_gemset too. But not that if you switch to other ruby version, e.g. 1.8.7, you have to do it again for 1.8.7@global.

Posted by Shaokun 23 May 2011 at 04:36AM