Thursday, September 19, 2013

Using Hudson and Liferay

This is one of those things that seems really intimidating when you first start, and then even more intimidating when you start Googling it and realize that there isn't much out there to help you, and what there is...   Isn't very helpful.  Once again, those resources all take for granted that the reader knows everything there is to know (which leaves me wondering what the purpose of the resource is).

Novices need love too.

So here's the scenario:  You need to stand up a Hudson system to handle your portlets (or whatever Liferay plugins) and have never used Hudson before.

Fear not.

It's actually not difficult at all.

Our setup here:
Server: CentOS
Portal: Liferay 6.1
Hudson: Eclipse Edition
Code Repo: GitHub

The first thing you must do is to get the latest installation guide from Hudson.  I found The Hudson Book to be pretty good and easy to read.

FOLLOW THOSE INSTRUCTIONS TO THE LETTER.  I'm not kidding about that.  Do it.  It's not complex.  In the case of my team, I installed it on a CentOS box as a service.  That gets you your basic Hudson installed.

Now, if this thing is living on the same box as your Liferay server, you'll need to tell Hudson to use a port other than the one your Liferay will be using.  In my case, I set it to port 8585 by doing the following:

Go to /etc/sysconfig and open the "hudson" file in your text editor.
Change HUDSON_HOME from port 8080 to port 8585
Save it.

Now, in my case, I had a problem where Hudson wouldn't start because it was pointing to a Java 1.5 JRE on my system and it required at least 1.6.  My JAVA_HOME variable was set to a Java 1.7 JDK but Hudson didn't use that.  Beware.  It looks in /usr/bin for your Java.  Our quick fix was to put a symbolic link in there to make it point to the correct Java version.

Now, I'm going to assume here that you either already have Liferay installed on your server, or that you know how.  There's plenty of info on that so go ahead and get that done then come back here.

All done?  Ok.  Next, you'll need the Liferay SDK on that machine.  Install it and configure it, using Liferay's documentation, so that the SDK is pointing to the instance of Liferay on your server.

Here's what's going to happen.  When Hudson pulls code from the repo, it's going to put it in the SDK and run the Ant command to use the build script that comes with Liferay to build and deploy the plugin.  That means that the hudson user needs to have the correct permissions on the SDK.  In our case, we simply changed the ownership of the SDK to a user group that the hudson user was a part of.  Keep in mind this also applied to the deploy folder in Liferay, as the Hudson user needs to be able to copy the .war file into it, and whatever user you're running Liferay under needs to be able to pull the file from that folder and delete it.

Now you'll need to go into Hudson and start setting up jobs.
In the Hudson interface, click "New Job"
Give the job a name and make sure "Build a free-style software job" is selected, then hit Ok
Most of these settings are a matter of preference and tuning, so you won't really know how they should be until after you run this for a while.  The ones you need in order to get Husdon working are the ones I'll mention.

Under Advanced Job Options (You may have to click the "Advanced" button to see this) check "Use custom workspace" and fill in the directory path where you want the code to go.  This should be in your Liferay SDK.  For example: "/opt/liferay/liferay-plugins-sdk-6.1.1/portlets/welcome-portlet" in the case of a portlet named "welcome-portlet."

Under Source code management, configure it to point to the project in your repo.  In our case, that's Github, so I selected Git and gave it the URL to the project repo (remember to include the .git extension at the end). 

If you want Hudson to automatically perform a build when the code rep is updated, you'll want to choose the Poll SCM trigger under "Build Triggers."  The schedule field takes a basic cron expression.  (For example, "0 * * * *" tells it to run every hour on the hour.)

 Under the "Build" section, you'll need to use Ant.  This is the default for how Liferay projects are built.  (You'll need Ant installed on your server.)  Select the Ant version you're using and in the "Targets" field simply enter "deploy."  This tells Hudson to run the deploy target on Ant just as you would in the command line if you were building the portlets manually.  When that happens, the plugin will be built and copied by Ant into the deploy folder and the process from Hudson's perspective is done.

1 comment:

  1. what to say i praise of this blog, which contains a lot of amazing information as well as the thoughtful writes.
    Graphic Design Rochester NY
    Web Designing Rochester NY
    Web Development Rochester NY