Friday, December 20, 2013
How to create a Maven Build Job with Hudson?
In this article we will see how to create a Simple Maven build job that would create WAR file with the help of Continuous Integration (CI) server.
1] To build a Maven 2/3 project (Legacy) Hudson takes advantage of your POM files and drastically reduces the configuration.
2] In the Source code management section select your “SCM”. In my case it’s “Apache Subversion”. Select it and specify the “Repository URL”.
If you repository have some credentials set to checkout the code , update the it.
3] Under the build section, in Root POM field specify the pom file name.
4] Do you believe that we have done with the maven build configuration setup in Hudson? The truth is, it’s completed, save the project. In Hudson main Dashboard page you could able to view all the projects created.
5] Once everything is done, just click the Build now button in the left pane of the Hudson console for action.
6] Just now open up the console to check the output.
That’s it! Please do let us know if you have any queries!
Friday, October 4, 2013
Hudson: A Continuous Integration Tool Master-Slave Configuration
1] One fascinating feature of Hudson is its endowment to run a job in a master-slave configuration, i.e., there would be a Hudson master machine which would take up all the requests like defining a job, configuring it, triggering it, etc., while there will be a set of slave machines on which the executions would actually happen.
2] Let’s say you want to define a job which has to be run on more than one platform. You define it in the Hudson master, the interface for all your configurations, and then tie it to all the machines that you would want to run the job on. The underlying mechanism of Hudson takes care of all the communication between the Hudson master and each of the slaves which are registered with it.
--> Now, we will see how to setup Hudson - the master and slave(s).
Setting up the Hudson Slave:
1] Open the Hudson URL localhost:7000 and go to Managed Hudson which is available in the Left sidebar.
2] Now go to the “Managed Nodes” option available under that page.
3] Now in that “Managed Nodes” page already master is exist, now we need to add the “Slaves” to it. In order add slave now just click the “New Node” option available in the left pane.
4] Specify the slave name now and select the “Dumb Slave” radio button now, finally click OK.
5] Now specify the number of executors, Remote File System Path and Select Launch Method as “Launch Slave agents on Unix Machine via SSH”. Along with also specify the remote machine details.
a] Hostname
b] Username
c] Password
d] SSH Port number
e] Java Path
And now, please don’t forgot to save it J
6] It’s easy to monitor the availability of slave using the “Log” option available in the left pane.
7] That’s it!! The slave is now added successfully to the master over SSH !!
8] Now initiate some build process, that build will be automatically triggered on the remote machine. See the attached snapshot for reference.
9] For verification go to the “Remote Slave – File System” specified at creation time of the slave. There you could able to see the directory workspace and all your associated build related files inside.
10] Thank you !!
Tuesday, April 30, 2013
How to create war file using ANT(Build Management Tool)?
What is Apache ANT ?
Apache ANT is software to perform automated build process .It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects.The most immediately noticeable difference between Ant and Make is that Ant uses XML to describe the build process and its dependencies, whereas Make uses Makefile format. By default the XML file is named
build.xml.What is the general flow of various targets involved in build.xml ?
Steps involved:
1. At the execution of this build.xml the default target specified is get called first.
<project name="firstProject" default="All" basedir=".">Now controlled is transfer to the target named All(case sensitive).
2. Target All depends on target dist.
<target name="All" depends="dist" description="Clean work dirs, then compile and create a WAR"/>3. Target dist depends on target compile at this step. In order to create a bundled WAR file we need set of compiled clas files and web pages.
<target name="dist" depends="compile" description="Create WAR file for binary distribution">
<war destfile="${dist.home}/firstProject.war">
<fileset dir="${work.home}"/>
<classes dir="${work.home}/WEB-INF/classes"/>
</war>
</target>
4. Before proceeding with compilation part , we must create a directory structure to place this class files and web project related JSP files. <target name="prepare" depends="clean" description="Create working dirs and copy static files to work dir">
<mkdir dir="${dist.home}"/> <mkdir dir="${work.home}/WEB-INF/classes"/>
<!-- Copy static HTML and JSP files to work dir –>
<copy todir="${work.home}">
<fileset dir="${web.home}"/>
</copy>
</target>
5. To make sure that all old files and folders are cleared, just proceed with clean up activity before preparation.<target name="clean" description="Delete old work and dist directories">
<delete dir="${work.home}"/>
<delete dir="${dist.home}"/>
</target>
Complete Build.xml used to create WAR:<?xml version="1.0" encoding="UTF-8"?>
<project name="firstProject" default="All" basedir=".">
<!-- Define the properties used by the build -->
<property name="app.name" value="Nielsen_Portal_New1"/>
<property name="tomcat.home" value="${basedir}/lib/tomcat-lib" />
<property name="struts.home" value="${basedir}/lib/struts-lib" />
<property name="hibernate.home" value="${basedir}/lib/hibernate-lib" />
<property name="axis2.home" value="${basedir}/lib/axis-lib" />
<property name="poi.home" value="${basedir}/lib/pom-lib" />
<property name="mysql.home" value="${basedir}/lib/mysql-lib" />
<property name="log4j.home" value="${basedir}/lib/log4j-lib" />
<property name="work.home" value="${basedir}/work"/>
<property name="dist.home" value="${basedir}/dist"/>
<property name="src.home" value="${basedir}/src"/>
<property name="web.home" value="${basedir}/WebContent"/>
<!-- Define the CLASSPATH -->
<path id="compile.classpath">
<fileset dir="${tomcat.home}">
<include name="*.jar"/>
</fileset>
<fileset dir="${struts.home}">
<include name="*.jar"/>
</fileset>
<fileset dir="${hibernate.home}">
<include name="*.jar"/>
</fileset>
<fileset dir="${axis2.home}">
<include name="*.jar"/>
</fileset>
<fileset dir="${poi.home}">
<include name="*.jar"/>
</fileset>
<fileset dir="${log4j.home}">
<include name="*.jar"/>
</fileset>
<fileset dir="${mysql.home}">
<include name="*.jar"/>
</fileset>
</path>
<target name="All" depends="dist" description="Clean work dirs, then compile and create a WAR"/>
<target name="clean" description="Delete old work and dist directories">
<delete dir="${work.home}"/>
<delete dir="${dist.home}"/>
</target>
<target name="prepare" depends="clean" description="Create working dirs and copy static files to work dir">
<mkdir dir="${dist.home}"/>
<mkdir dir="${work.home}/WEB-INF/classes"/>
<!-- Copy static HTML and JSP files to work dir -->
<copy todir="${work.home}">
<fileset dir="${web.home}"/>
</copy>
</target>
<target name="compile" depends="prepare"
description="Compile Java sources and copy to WEB-INF/classes dir">
<javac srcdir="${src.home}" destdir="${work.home}/WEB-INF/classes" debug="true" debuglevel="lines,vars,source">
<classpath refid="compile.classpath"/>
</javac> <copy todir="${work.home}/WEB-INF/classes">
<fileset dir="${src.home}" excludes="**/*.java"/>
</copy>
</target>
<target name="dist" depends="compile"
description="Create WAR file for binary distribution">
<war destfile="${dist.home}/firstProject.war">
<fileset dir="${work.home}"/>
<classes dir="${work.home}/WEB-INF/classes"/>
</war>
</target>
</project>
That’s it !! Its’ very simple, in the forthcoming posts we will see how to create a bundled EAR in Archived form and Exploded form. Leave a reply if you have any doubts regarding this post !!References:
1] http://en.wikipedia.org/wiki/Apache_Ant
2] http://en.wikipedia.org/wiki/List_of_build_automation_software
Sunday, March 17, 2013
Hudson : A continuous Integration Server
• Continuous integration (CI) is a set of practices intended to ease and stabilize the process of creating software builds. CI assists development teams with the following challenges:
1] Software build automation
2] Continuous automated build verification
3] Continuous automated build testing
4] Post-build procedure automation
What is Hudson ?
Hudson is a continuous integration (CI) tool written in Java, which runs in a servlet container, such as Apache Tomcat or the GlassFish application server. It supports SCM tools including CVS, Subversion, Git, Perforce and Clearcase and can execute Apache Ant and Apache Maven based projects, as well as arbitrary shell scripts and Windows batch commands. The primary developer of Hudson was Kohsuke Kawaguchi, who worked for Sun Microsystems at the time. Released under the MIT License, Hudson is free software.
Installation Hudson?
•Distributions: Hudson can be downloaded from both eclipse.org and hudson-ci.org. More information about the available distributions can be found here.
•Prerequisites : Hudson only needs a Java 6 or newer runtime. An internet connection will be required if you want to be able to install and auto-update plug-ins.
•Install: You can install Hudson on Windows and Linux in 2 different ways.
1] Standalone War file
2] Deployed War file
Method 1: Testing Purpose:
After you download Hudson.war, you can launch it by executing java -jar Hudson.war. This is mostly useful for testing purposes.
Hudson CI Server Initial Setup:
Method 2: Production Purpose:
For production we have to use native packages for simplified install or deployment in a servlet container that supports Servlet 2.4/JSP 2.0 or later, such as Weblogic, Glassfish, Tomcat 5, JBoss, Jetty 6, etc. See Containers for more about container-specific installation instruction.
Here we deployed the downloaded hudson.war file in Weblogic Application Server !! Now we can access the deployed application.
References:
http://en.wikipedia.org/wiki/Hudson_(software)
http://wiki.eclipse.org/Hudson-ci/Installing_Hudson
