Integrating Jenkins with Sauce OnDemand



Installation

If you already have a Jenkins server, skip this section. If you need one, we recommend using Amazon's Elastic Computing Cloud (EC2). Set up an Ubuntu server with one of the official images using the Ubuntu EC2 Starters Guide.

Once you have a basic Ubuntu machine up and running, SSH into it and install Jenkins:

ssh -i <path-to-your-ec2-private-key> ubuntu@<public-DNS-address-of-your-instance>
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install -y sun-java6-jdk daemon git-core
sudo apt-get install -y --no-install-recommends ant ant-optional
wget -O /tmp/key http://hudson-ci.org/debian/hudson-ci.org.key
sudo apt-key add /tmp/key
wget -O /tmp/hudson.deb http://hudson-ci.org/latest/debian/hudson.deb
sudo dpkg --install /tmp/hudson.deb
sudo /etc/init.d/hudson start
sudo usermod -c Jenkins,,, hudson

You now have a Jenkins master server up and running that you can get to at http://<public-DNS-address-of-your-instance>:8080/.

Configuring Jenkins

  1. Navigate to your Jenkins server's main page
  2. Select Manage Jenkins -> Manage Plugins
  3. Go to the Available tab and check the box next to "Sauce OnDemand Plugin"
  4. Scroll to the bottom of the page and click Install
  5. On the next page, wait for the plugin to finish installing, then click "Restart When No Jobs Are Running"
  6. When you have returned to the Jenkins home page, go to Manage Jenkins -> Configure System and enter your Sauce OnDemand credentials:

Setting up your project

Setting up projects in Jenkins depends on your particular environment. Refer to the Jenkins documentation for details. To assist in getting started, here is the set up process for a simple example Java servlet tested with JUnit and Selenium. This example setup is based on a simple "Hello World" Java servlet available on GitHub.

  1. To begin, install the GitHub plugin for Jenkins:
  2. Restart Jenkins to finish the installation, and create a new job:
  3. Select "Build a free-style software project," give your new job a name, and click OK:
  4. Enter a description for your project. For this example, set git://github.com/epall/hudson-demo.git as a Git Repository for the project:
  5. This project uses Sauce Connect to have Sauce OnDemand connect with the application running on the Jenkins buildslave. Set up the Sauce Connect tunnel with the following configuration:
  6. To get the project to build and publish test reports, add a build step to invoke the Ant target "test":
  7. Set up the project to publish JUnit test result reports from test-reports/*.xml:
  8. Save the new job and click "Build Now." After about two minutes, you should see a successful build for the project in Jenkins.

Congratulations! You've set up your first Sauce OnDemand build in Jenkins!


Integrating with Sauce Tunnels

To test internal applications that sit behind a firewall, Sauce OnDemand uses Sauce Connect to securely access your application. Jenkins can manage, start and stop Sauce Connect for you automatially, making Sauce OnDemand a drop-in replacement for your internal Selenium test servers.

You'll still need to modify your Selenium tests to connect to the Sauce OnDemand servers, and choose which browser versions to run your test against. See our Getting Started guide for examples in several popular languages.

  1. To get started with an existing Jenkins installation, you'll first need to install the Sauce OnDemand Plugin for Jenkins:
  2. Once you've installed the plugin and re-started Jenkins, you'll need to configure your Sauce OnDemand credentials so Jenkins can connect to OnDemand and use manage Sauce Connect:
  3. For each project you want to test with Sauce OnDemand, go into the project's 'Configure Page' and check the box for "Sauce OnDemand SSH tunnel." Enter 'localhost' in the 'Selenium Host' field, and '4445' in the 'Selenium Port' field. Values entered in these fields will be stored in the SAUCE_ONDEMAND_HOST and SAUCE_ONDEMAND_PORT environment variables.
  4. Save the configuration and build your project!