Thursday, July 7, 2011

Hudson-Subversion-Selenium Continuous Integration

1. Continuous Integration with Hudson
1.1. Continuous Integration Overview
1.2. Hudson
1.3. Requirements for using Hudson
2. Installation
2.1. JAVA JDK 1.6, Apache Ant
2.2 Installing Visual SVN Server in server machine.
2.3 Installing Tortoise SVN in Client Machine.
3. Hudson
3.1 Configure Hudson
4 Importing Working Build Script into the Tortoise SVN
5 Configuring a build job in Hudson
6. Working Flow (SVN HUDSON)


1. Continuous Integration with Hudson

1.1. Continuous Integration Overview

Continuous integration is a process in which all development work is integrated at a predefined time or event and the resulting works is automatically tested and build. The idea is that development errors are identified very early in the process.

1.2Hudson

Hudson is one open source tool to perform Continuous Integration. The basic functionality of Hudson is to monitor a SCM (Source Control System) and if changes occurs to start and monitor a build system (for example Apache Ant or Maven). Hudson will monitor the whole process and provide reporting functionality and notification functionality to report success or errors.
Hudson can be extended by additional plug-in.

1.3. Requirements for using Hudson

To use Hudson you need:
  • An accessible source code repository, e.g. subversion, with your code checked in.
  • A working build script, e.g. ant script, checked into the repository

2. Installation

2.1 Install Java JDK 1.6, Apache ANT

For the usage of Hudson you need to setup Apache Ant as a build tool.

2.2 Install VisualSvnServer in Server Machine.

VisualSVN Server allows you to easily install and manage a fully-functional Subversion server on the Windows platform.

Step1: Copy the VisualSVN Server software from the following Location to Server Machine.

Step2: Install VisualSvnServer Software.









Step3: Click on Finish button then we get the following Window.

Step4: Create the new users in Visual Svn Server.










Click on create new user in Subversion Authentication.
Created Users are listed in Users.






Step5: Create new Repository in Visual Svn Server.

Right click on Repositories ----->click on Create new Repository--->Type Repository Name---->Select default structure check box---->Click on ok button
















2.3 Install TortoiseSVN

TortoiseSVN is a free open-source client for the Subversion version control system.TortoiseSVN manages files and directories over time. Files are stored in a central repository.
Step1: Install TortoiseSVN in your machine. 
Step2: After installing, click on the right mouse button on any location then you will see the following list of properties.



Step3: Select Tortoise SVN --->settings. --->Choose Network
Step4: Check Enable Proxy Server



Step5: Enter Windows Server IP-Address and the port number (E.g.: Server: 172.16.2.88, Port: 80)
  • Enter Username and Password of VisualSvnServer(E.g.: Username :admin Password :XXX)
  • Click on Apply and Ok

Step:6 Click on right mouse button ---> Select SvnrepoBrowser



    Step:7  Enter Username and password which we created in svnserver.


     
     
     
    2.4. Hudson
    Step1:
    Download the "Hudson. War" file from Hudson Homepage or from the following Location.
    Step2: place the Hudson. war file in your local directory.
    Ex: C:\hudson
    Step3: Run the hudson.war file from the command prompt.

    Step4: Hudson installation should be available under "http://localhost:8080

    2.5 CONFIGURE HUDSON

    Go to Hudson under "http://localhost:8080/" and click "Manage Hudson" and then "Configure System"





    On the system configuration page, note the first item in the list, which is Home directory. This is where Hudson performs all its work and stores all its configuration.



    1) JDK and ANT: In order to configure both a JDK and an Ant instance, click the Add button under each section. A set of fields will expand out under the configuration section.
    In each case, you assign an arbitrary name identifying the JDK and Ant installation. You need to assign these because multiple instances can be configured, depending on the needs of your project; for instance, you might have Java JDK instances for 1.4, 1.6, and 1.7, as well as Ant 1.6 and 1.7. When you configure your project build, you will select the instance you want to use.

    When Invalid directory is entered, Hudson immediately notifies you that the fields representing JAVA_HOME and ANT_HOME are not valid directories. When a valid directory is entered, these warning will go away. This is a simple example of Hudson's user-friendliness: it gives you immediate feedback rather than waiting for an error to occur when the directory cannot be found.

    2) Subversion: Configure the Subversion Version and Subversion Revision Policy in Subversion part.

    Note: Update the Subversion Version to 2.0.0 to 2.0.1
    Hudson Homepage -> Manage Hudson -->Manage Plug-in ->Updates tab ->Select Subversion plug-in -->Click on install.


    3) E-mail Notifications:
    The last important entry on this page is the SMTP configuration, which allows Hudson to email you notifications of important events like failed builds. If your SMTP server requires authentication, you will need to use the advanced options. If you have a valid Gmail account, you can use the Google SMTP server and your Gmail address.

    Note:
    Install Email-ext plug-in. This plug-in allows you to configure every aspect of email notifications. You can customize when an email is sent, who should receive it, and what the email says.
    Path: Hudson Homepage--->Manage Hudson--->ManagePlugins--->Available---> Build Notifiers → Email ext plug-in → Install (right corner of the page)
    Note:
    After installing the Email plug-in. Restart the Hudson server.
    To Close the Hudson Server:
    Go to Command Prompt where Hudson server is running→ Press Ctrl+C
    To Restart Hudson Subversion:
    Command Prompt → java -jar huson.war

    2.6 Importing Working Build Script into the Tortoise SVN

    Step1: Copy the Working Build Script into the temporary folder.

    Step2: Import temporary folder which contains Working Build Script into the svn Trunk.
    Right Click on temporary folder---->Click on svnimport


    Step3:Click on OK button and browse the project tortoise svn.




    2.7 Configuring a build job in Hudson

    On the main Hudson page at http://localhost:8080/, click the New Job link. There are several options for new job types.
    Step1: Enter the Job name (ex: Hudson_Subversion), select Build a free-style software project and click on OK button.



    Step2: The next form that comes up is the bulk of the new job configuration, and it is quite long. The details of this configuration are listed below. On the right of each option on this form, there is a little question-mark (?) icon. Do not hesitate to click on it for a more detailed explanation of any configuration option.

    Step3:
    Project name: Hudson_Subversion
    • Description: A free-form field where you can describe the build job.
    • Discard old builds: Hudson will retain a history of prior builds unless you check this box.
    • This build is parameterized: If you select this option, Hudson will allow you to provide a set of arbitrary parameters using name-value pairs that will be passed to the build process. Configured parameters will be set as environmental variables in the environment of the running build.
    • Disable build: If this is checked, builds for this job will not be executed until the option is disabled.


    Step4: Source Code Management
    The three options available by default are:
    • Subversion
    • CVS
    • None
    When you select Subversion, a configuration section expands into the form.






    Click on Update credentials link to Authenticate Subversion.



    Step5: Build TRIGGERS
    A Hudson job can be configured to build in response to build activity on a
    Hudson instance, in accordance with a regular schedule, or as a reaction to activity in an SCM system. Build triggers are configured on a Project's Configuration screen and the section is shown in below Figure.






    Build after other projects are built: This option supports an assembly line -- job dependencies where one job depends on the output of another -- or possible scenarios where you simply want to group some related project builds together. When you select this, you will be provided with a field to enter the comma-separated names of the other projects after which this build should run.
    Poll SCM: This is the classic option for CI systems. When you select this option, you can specify a cron expression that defines how often Hudson should check your source repository for changes. If changes are found, a build will be executed. For example, the expression 0,15,30,45 * * * * will make Hudson check your repository for changes every 15 minutes. See the Quartz CronTrigger javadoc for additional details on this cron syntax.
    Build periodically: This option (also defined using a cron expression) simply instructs Hudson to build the project on a specific frequency regardless of changes in SCM. This may be helpful if you want to run some test cases where the target test environment is somehow modified periodically but the SCM is static with respect to this job.

    Note: */5 * * * * means It monitors the svn for every 5 minutes ,if any modification is done to your project or version revised ,Hudson automatically rebuilds and executes the job.
    Step6:
    Add build step: Click this button to add a directive to run a build script. Your directive can be one of the following:
    • Execute shell
    • Execute Windows batch command
    • Invoke Ant
    • Invoke top-level Maven targets







    Step7:
    E-mail notification: you can enter multiple email addresses separated by white spaces, after job execution completion email notifications will be sent to entered recipients.





    Step8: Click on save button.













    3. Working Flow (SVN HUDSON)
    Step1: CheckOut the Project to Your Local system From SVN.

    Step2: Do the required changes in your project From Checkout Directory then commit the Changes.
    By Right Click on Changed File---->SVN Commit

    Step3: Now new build will be executed in Hudson.

    Note: Build is executed in Hudson for every change in SVN.

    Step4: After completing the build execution, result will be sent to email recipient

    2 comments:

    1. Amazing article.

      I am looking for Hudson configuration for sometime. I see a lot of Jenkins tutorial but Hudson only few of them. Yours stand out out of those few.

      Great article. Keep writing more. For more detailed articles or forums on Selenium, please check out selenium training centers in chennai

      ReplyDelete