1. Install Hudson

– Open PuTYY and connect to Server. (If unavailable, click here to download)

– Run 4 below commands:

sudo apt-get install default-jdk
sudo sh -c "echo 'deb http://hudson-ci.org/debian /' > /etc/apt/sources.list.d/hudson.list"
sudo apt-get update
sudo apt-get install hudson

– Reboot server: reboot

– Check if Hudson is running: service hudson status

2. Install Plug-in

a) Open URL, e.g.: http://192.168.70.17:8080

b) Install following plugins:

Plug-in

  • SCP plugin
  • Hudson Subversion Plug-in
  • Hudson CVS Plug-in
  • Hudson Maven3 Plugin
  • These plugins are default choices (Hudson BIRT Charts Plugin ; JNA Native Support Plugin ; XPath Provider Plugin)

Untitled

c) Finish

Untitled

3. Install Maven

a) In PuTTY, run apt-get install maven to install Maven.

b) This will take a lot of time.

4) Configure System

a) Click Manage Hudson. Then click Configure System.

b) Configure

  • Check JAVA_HOME: printenv JAVA_HOME

Untitled

If you don’t see the path of this variable, reference tips at the last of this document.

  • Configure JDK

Untitled

c) Configure Maven 3

  • Check MAVEN_HOME: printenv MAVEN_HOME
  • Configure Maven 3

Untitled

d) Configure SCP

Untitled

Tips: You can configure Hudson to deploy your project to different servers by clicking Add button to create more SCP sites.

e) Click Save.

5. Configure in your project

  • In file pom.xml, add these codes below:
<project>
</dependencies>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.5</version>
  <scope>provided</scope>
  </dependency>
</dependencies>

<profiles>
<profile>
  		<id>geronimoDev</id> // Used in “Execute shell”
<build>
  			<finalName>TestSystem</finalName> // .war file name
  </build>
<properties>
  <app.contextRoot>/testsystem</app.contextRoot>
  <app.artifactId>TestSystem</app.artifactId>
  <app.state>Development</app.state>
  <app.environment>Development</app.environment>
  </properties>
</profile>
</profiles>
</project>

6. Create New Job

a) Click New Job. Enter a job name. Then click OK.

b) Choose Subversion in Source Code Management

c) Fill in the form:

  • Repository URL – The link of the folder containing your project on SVN. It likes this:

Untitled

 

  • Click enter credential
  • Choose User name/password
  • Enter your User name and Password.
  • Click OK. Click Close, then Save.

Untitled

d) Check-out Strategy:

Untitled

e) In tab Build

  • Click Add build step, select Execute shell
  • In Command, enter:
mvn clean package -P geronimoDev -Dmaven.test.skip=false

(true: skip Unit Test. false: include Unit Test)

Untitled

f) Check Publish artifacts to SCP Repository in Post-built Actions

  • Choose SCP site to deploy if you have many servers.

Untitled

  • Click Add.
  • Enter in Source and Destination (Source where the war file stored can check in Workspace/target)

Untitled

7. Build Job

a) Click Build button

Untitled

b) Check Console Output. While Hudson is building, you should open Geronimo (choose Web Apps (WAR)).

c) When Hudson builds “SUCCESS”, you refresh Geronimo to see the change: the old project is removed to deploy the new one. After about 30 seconds, this process will finish, you refresh the web again, and the project will appear with your changes updated.

Untitled

* TIP

1. Export variable if don’t see the path when check. (PuTTY)

  • nano /etc/profile –> move to the last
  • export MAVEN_HOME=’/usr/share/maven’
  • Ctrl+X –> Y
  • export MAVEN_HOME=’/usr/share/maven’

(Similar with other variables, maybe for JAVA_HOME, SONAR_RUNNER_HOME)

2. Many job

– In real project, you will have a big workspace, and you will add Sonar and Test Coverage  (JaCoCo) later. When you build project, it will takes a lot of time.

– So, you should create many jobs for difference purposes, such as:

  • Job only for Testing (include Unit Test, not deploy, not Sonar, not JaCoCo)
  • Job only for Deploy (skip Test, not Sonar, not JaCoCo)

Untitled

– So that you can save a lot of time when you build.

3. War file does not uninstall automatically

– If you deploy by hand (export in eclipse, then install war file in Geronimo), the next time you deploy by Hudson, the war file in system will be replaced by the new one (you can check via WinSCP, the path is “/var/opt/geronimo/deploy”). But on the web interface Geronimo, the old one still remains, so your project won’t be updated.

– You can read log file “geronimo.log” by the path “/var/opt/geronimo/var/log” to see the problem. The main reason is that you deployed war file by hand, so Hudson can’t uninstall the old one automatically on the web Geronimo.

– In this case, you just click uninstall in Geronimo, then click build in Hudson to deploy again. And it goes work correctly so far.

4. Function in to build Hudson

validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy, pre-clean, clean, post-clean.

Resources:

– Document

– https://plus.google.com/photos/104055469580103733204/albums/6044373576123078081?authkey=CMTD9dLr6q_eowE

  1. System Configurations;
  2. Full job:
  3. Just for Deploy
  4. Just for Test

Ref: