Using JUnit, Ant and Hudson for Continuous Integration
Part 3: Using Hudson for Continuous Integration
Hudson is a powerful and widely used open source continuous integration server providing development teams with a reliable way to monitor changes in source control and trigger a variety of builds. Hudson excels at integrating with almost every tool you can think of. Use Apache Maven, Apache Ant, or Gradle (or anything you can start with a command line script) for builds, and send messages via email, SMS, IRC, and Skype for notifications. In addition to providing a platform for continuous integration builds, Hudson can also be extended to support software releases, documentation, monitoring, and a number of use cases secondary to continuous integration.
show more or less

With continuous integration, the system completes a build, test, deploy, and integration in response to every single commit. If a developer in the web application group checks in code, Hudson kicks off a build, runs unit tests, deploys the code to a new server, and performs a set of integration tests. If this build fails or the tests encounter an unexpected condition, everyone is notified of this failure. With continuous integration, no one needs to drop everything and run a release build, these builds are generated every single day, and in the most mature environments, a fully tested and verified system can be deployed to production at any time. In other words, when you automate build, test, and verify using a tool like Hudson you can continue developing your applications without having to wait (or synchronize) on some manual build, test, verify process. Making these processes automatic has another important side-effect, it makes the development process more scaleable. When your teams don’t have to stop to actively test and collaborate with one another, it is much easier to add additional developers to a project. Without continuous integration you have to stop and synchronize release schedules. With continuous integration you reduce the risk associated with a particular software development cycle.

For more details about Hudson, you can refer to Hudson Documentation.

Step 1: Install Hudson Server
  1. Download the latest hudson.war file from

    The Hudson internet site
  2. Open a command window from the folder where you downloaded the Hudson file.

    Opening a Command window from Windows Explorer
  3. In the command window type: java -jar hudson-2.2.0.war --httpPort=8989 to install Hudson and run it on port 8989.

    The Command window
  4. Wait for Hudson to finish initializing.

    The Command window
  5. Open a browser window and type http://localhost:8989/ to launch the Hudson console. Wait for the Hudson dashboard page to load.

    The Hudson console in a browser
  6. In the Hudson dashboard page, select the Manage Hudson link.

    Selecting the Manage Hudson link from the Hudson console

    Notice that in Microsoft Windows environment, you can create a Windows service for Hudson and have the service start automatically. Refer to the following link for instructions on how to install Hudson as a Windows service.

  7. In the Manage Hudson page, select the Manage Plugins link.

    Selecting the Manage Plugins link from the Hudson console
  8. In the Plugin Manager, click the Installed tab.

    Selecting the Installed tab from the Hudson console
  9. Note that the list of installed plugins includes the Hudson Subversion Plug-in. Click the Back to Dashboard link.

    Selecting the Back to Dashboard from the Hudson console
Step 2: Configure Hudson Server

To indicate to Hudson that ojdeploy and Ant are used for building the test, perform the following steps:

  1. Back in the Hudson Dashboard page, click the Manage Hudson link.

    Selecting the Manage Hudson link from the Hudson console
  2. In the Manage Hudson page, click the Configure System link.

    Selecting the Configure System link from the Hudson console
  3. Select the Environment variables check box in the Global Properties section, then click the Add button to add a key-value pair to specify the location of the ojdeploy executable. In your case, you are not going to use the ojdeploy command, but you might need to use the command later if you choose to include packaging tasks in future builds. Therefore, it's a good idea to learn how to configure it now.

    Adding environment variables to the project
  4. In the name field, type OJDEPLOY. Using Windows Explorer, locate the ojdeploy.exe file and copy its path in the value field.The Global properties for ojdeploy

  5. Scroll down to the JDK section to specify where it is located. Click the Add JDK button.

    Clicking the Add JDK button
  6. Type JDK as the JDK Name, and in the JAVA_HOME field, specify the path to the jdk folder.

    Specifying the jdk location and name
  7. Scroll down the Manage Hudson page, and in the Ant section, click the Add Ant button.

    Selecting the Add Ant option
  8. In the Ant installations section, deselect the Install automatically check box, and then type Ant_Default as the Ant Name. Using Windows Explorer, locate the ant folder and copy its path in the ANT_HOME field.

    Copying the Ant path
  9. Scroll down to the bottom of the page, and click the Save button.

    Clicking the Save button

    At this point, notice that you can set up an email notification. You learn how to do this later.

Step 3: Create a Job for your CI Build
  1. Back in the Hudson Dashboard, click the create new jobs link.

    Selecting the Manage Hudson link and then the create new jobs one from the Hudson console
  2. In the Job name field, type Hudson_Testing, select the Build a free-style software project option, and click OK.

    Entering a Job name
  3. Because you are using Subversion as the repository tool in JDeveloper, you need to specify the location of the Subversion resource files. In the Project page, select Subversion in the Source Code Management section.

    Selecting Subversion as the Source Code Management tool
  4. In the Repository URL field, type the URL of your repository.

    Repository URL is required for Subversion
  5. If you don't know the URL, you can copy it from the Versioning Navigator in JDeveloper. Right-click MyRepostory, and select Copy URL.

    Getting the URL from the context menu
  6. Paste the URL into the Repository URL field. In the Check-out Strategy field, select the Clean workspace and then checkout option from the list.

    Pasting the URL
  7. Scroll down and in the Build section, click the Ant build step button, and select the Invoke Ant option.

    In the Build section, selecting the Invoke Ant option
  8. In the Build section under Invoke Ant, select Ant_Default for the Ant version. Type all in the Targets field.

    Typing the name of the Ant Version and of the target

    Click the Advanced button

  9. In the Build File field, type JUnitTests/build.xml to indicate the relative location of the build.xml file.

    Adding the build.xml relative address in the advanced properties
  10. Click the Save button at the bottom of the page.

Step 4: Run the Job

Now that your job is defined, you can run it.

  1. In the Hudson_Testing project, click the Build Now link to run the test.

    Selecting the Build Now link from the Hudson console
  2. Wait for the build to end. Then click the Latest Console output link to see the status.

    Selecting the latest console output from the Hudson console
  3. The Blue circle indicates a successful run. Notice the list of executed Ant targets in the bottom left section of the page.

    Displaying the console output
  4. Scroll down to review all details.

    Displaying the console output

    At this point, you have used Hudson to call and execute the all Ant target that you previously executed from JDeveloper.

Step 5: Install the TPC Plugin

To allow interaction between Hudson and TPC, you need to install the TPC plugin for Hudson. To install the plugin, perform the following actions:

  1. Go to the Hudson plugins site and click the plugins link.

    Index of Hudson  Downloads
  2. Select the HudsonTpcPlugin link.

    Index of Hudson plugins Downloads
  3. Select the latest build folder.

    Index of Hudson plugins for Tpc Downloads
  4. Right-click the HudsonTpcPlugin.hpi file, and select the Save Target As option. Download the file in the directory of your choice (Hudson/plugin in this case).

    Saving the Hudson-tpc localy
  5. In the Hudson dashboard, click the Manage Hudson link.

    The Hudson dashboard
  6. Click the Manage Plugins link.

    Clicking the Manage Plugins link from the Hudson console
  7. Click the Advanced tab in the Plugin Manager page.

    Clicking the Advanced tab in the Plugin manager
  8. In the Upload Plugin section, indicate the location of the HudsonTpcPlugin.hpi file and click the Upload button.

    Uploading the downloaded file for Tpc
  9. Click the Installed tab to see the status of the new plugin. Notice the warning indicating that you need to stop and restart Hudson to activate the plugin.

    Clicking the Installed tab
  10. Click the Hudson link to go back to the Hudson dashboard, and click the Manage Hudson link.

    Clicking the Manage Hudson link
  11. Scroll down and click the Prepare for Shutdown link.

    Clicking the Prepare for shutdown link
  12. Go to the Command window where Hudson is running and stop it (press Ctrl + C).

  13. Close your Hudson browser window, and restart Hudson from the command line by using the command java -jar hudson-2.2.0.war --httpPort=8989.

    The command window restarting Hudson
  14. Restart the Hudson Console in a browser window by typing localhost:8989 as the URL, then click Manage Hudson and Manage Plugins.

    Clicking the Manage Plugins link
  15. Click the Installed tab. The HudsonTpcPlugin should be present and ready for use.

    The Tpc plugin appears in the Installed pane
Step 6: Automate an Email Alert System

You can configure Hudson to send an email to a specific email address when a build failure occurs.

  1. Back in the Hudson dashboard, click the Manage Hudson link and then the Configure System link.

    Clicking the Configure System link from the dashboard
  2. Scroll down to the E-mail Notification section, and specify the SMTP server address and other details about the notification. In this example, there is a local SMTP server installed. Click the Advanced button to specify additional properties.

    In the Email notification, clicking the Advanced button
  3. Select the Use SMTP Authentication check box, and specify additional information to use SMTP authentication. Click the Test configuration by sending e-mail to System Admin Address button.

    Having typed all email info, clicking the Test Configuration button
  4. Click the Save button.

    Saving after sucessful email notification
  5. Open your email to verify that you received the notification.

    The Test email coming from Hudson
  6. Return to the Hudson dashboard and select the Hudson_Testing project. Click the Configure link.

    Clicking the Configure link
  7. Scroll down to the Post-build Actions section, and select the E-mail Notification check box. By default Hudson notifies the indicated users only when the build operation fails. If you want to get notified on success, you need to install the Hudson Email Extension Plugin.

    Selecting the Email checkbox
  8. In the Recipients field, type the email addresses of the persons in the team:,, Select the two check boxes to send alerts in both scenarios.

    Specifying the email addresses

    Click the Save button.

Step 7: Send Hudson Feedback to JDeveloper Through TPC

You can configure Hudson to use TPC to deliver information about test results to JDeveloper.

  1. In the Hudson_Testing page, click the Configure link to refine the project.

    Clicking the Configure link
  2. Scroll down to the Post-build Actions section, and select the Publish JUnit test result report check box.

    checking the Publish JUnit test result report checkbox
  3. Specify the Hudson relative path and the file name of the report file. For example: JUnitTests\testResults\

    Specifying the Hudson relative path and the filename of the report file
  4. Select the Publish test results to Oracle Team Productivity Center check box.

    Checking the Publish test results to Oracle Team Productivity Center
  5. Type as the URL of Oracle TPC Server and enter mdavis/Welcome1 as the TPC username/password of the user you want to inform.

    Typing as the URL of Oracle TPC Server and enter mdavis/Welcome1
  6. Click the Test Connection button to validate the connection.

    Clicking the Test Connection button

    Scroll down and click the Save button.

  7. Switch to JDeveloper. In the Hudson Model project under model.entities, open the Departments entity.

    The Application Navigator in JDev
  8. Click the Attributes tab, and select the DepartmentName attribute. In the UI Hints tab, type Department Name as the label.

    The Departments entity.
  9. Click the Save All The SaveAll icon on JDev main toolbar. icon on the JDeveloper menu bar, or select File > Save All from the main menu.

  10. Right-click in the Hudson Application and select Versioning > Commit Working Copy.

    Commiting the changes
  11. In the Commit Working Copy dialog, type UI Hints changes and click OK.

    the Commit Working Copy dialog

    Next, you run a build and see how JDeveloper receives information about the build from Hudson.

  12. Return to the Hudson page and click the Hudson_Testing link to reopen the job.

    Clicking the Hudson_Testing
  13. Click the Build Now link to launch the job.

    Clicking the Build Now link
  14. When the build is complete, click the Latest Console output link and scroll down to see the execution report.

    The Latest Console output

    Notice the message indicating that the result will be sent to Oracle Team Productivity Server. Because the build was successful, no email notifications are sent.

  15. Go back to JDeveloper, and from the main menu select View > Team > Build Dashboard.

    Calling the Build Dashboard option from jdev
  16. In the Build Dashboard pane in JDeveloper, click the Hudson_Testing link.

    The Dashboard pane
  17. The Hudson_Testing report shows details about the execution.

    The Hudson_Testing report
  18. From the Show drop-down list, select All Tests.

    Selecting All Tests option
  19. See the detailed status at each step of the build.

    The detailed status
  20. Click the Build Dashboard tab and then click the Hudson_Testing row to activate the Related Transactions pane. The Related Transactions pane indicates the versioning number (19 in this example) of the latest versioned element.

    The Build Dashboard tab
  21. Now that the connection between Hudson, TPC, and JDeveloper is established, you receive alerts each time Hudson executes a new build.

    Hudson alert in Jdev.

You've successfully completed this tutorial, which illustrates how to implement a continuous integration process.

In this tutorial, you learned how to configure your environment and use testing tools for continuous integration development management. You learned how to: To learn more about JDeveloper, JUnit, Ant, and Hudson, refer to:

Bookmark Print Expand all | Hide all

Did you find this page helpful?

Copyright © 2011, Oracle and/or its affiliates. All rights reserved.