Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Using Jenkins as Continuous Build Software

This is a quote from http://jenkins-ci.org/content/about-jenkins-ci:

"In a nutshell Jenkins CI is the leading open-source continuous integration server. Built with Java, it provides 800 plugins to support building and testing virtually any project."

Overview

Jenkins is a free open-source continuous build software package. It is managed by the Jenkins CI community. It is well suited for Java based projects, and some of the more notable features include:

  • Plugins for many popular builders such as Ant, Maven, ...; source control such as CVS, SVN, Git, Mercurial, ...; integration with GitHub through various plugins; notification via email and and other means; authentication via default container authentication/OpenID/Custom users/...
  • Other 3{^}rd^ part extensions for lots of other nice features.
  • Multiple jobs can be made to run at the same time, even on multiple master/slave Jenkins nodes and, using some plugins this can be configured around a number of available external "resources".
  • Groovy scripts can be run directly from the web interface against a Jenkins API.
  • Open source so extensible and customizable.
  • Web application - the entire build/job configuration can be done via a web browser.

Installing Jenkins

Download and install Jenkins native package from http://jenkins-ci.org/. Jenkins can also be deployed as a .war file in containers such as Tomcat, but the configuration would be identical.

For the purpose of this tutorial we will use the native Jenkins stand-alone installer.

You should now be able to access Jenkins at http://localhost:8080. This tutorial is based on a native Windows service installation, but it should be similar on other OSes as well.

Configuration Tips

As Jenkins and Servoy are both Java driven applications, they share some Java technologies, and by default, share port configurations as well. If you plan to run Jenkins and Servoy Application Server on the same machine, port changes will need to be made one application or the other in order for the applications to work properly.

Only one or the other needs to be modified, not both.

Changing ports for a Servoy Application Server installation is detailed here.

To change port configurations for Jenkins instead, modify the jenkins.xml file found in the Jenkins main folder. See the section below:

jenkins.xml
  <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080</arguments>

Note that "--httpPort=8080" is in conflict with Servoy Application Server default port. Change this port to any other available port on the machine (for example 8085) then restart the Jenkins service. The new URL to access Jenkins will be http://localhost:8085. (If you plan to install Jenkins as a .war inside another container such as tomcat, then that container's configuration determines the port and the URL will be something like http://localhost:8085/jenkins)

Jenkins is fully configurable from the browser. It has many useful plugins. If you think you need something, look through the available plugins. What you need is probably already available.

In this tutorial we will use two plugins (to install them go - in the browser - to "Manage Jenkins" -> "Manage plugins"):

  • openID plugin (allows authentication based on google account (or company Google account) or any other account that provides OpenID authentication)
  • build timeout plugin (makes sure jobs will automatically be stopped after a timeout - so your build fails if it take too long for some reason, instead of just never ending)

Some plugins that we will use such as SVN plugin are pre-installed.

Configure security using openID (skip this step if you are not interested in authentication on the Jenkins server)

  • go to "Manage Jenkins" -> "Configure global security"
  • check "Enable security"
  • choose "OpenID SSO" as "Security Realm" and in the Provider URL field put: https://www.google.com/accounts/o8/id
  • choose "Matrix-based" security
  • type your google username in "User/group to add" and click on "Add" button
  • grant yourself all rights by checking all checkboxes in your user's row
  • uncheck all checkboxes in the "Anonymous" row, except for "Job - Discover" (this one allows people to get prompted with the login when try to access a job's URL). Please do this only after you granted yourself all rights, otherwise noone will be able to access Jenkins.
  • click on "Save"

Now you should be the only one that can access the Jenkins server using your google credentials.

You can add any other people and configure their rights as needed now.

Note: Jenkins access can be configured in other ways as well, if you don't have a google/other openID account or you just want to use something else (LDAP/custom users).

Other things to configure

Here are some settings you should/could tweak in "Manage Jenkins" -> "Configure System":

  • if you don't have Ant installed, in "Ant" section add a new installation, give it a name and check "Install automatically".
  • "# of executors": set it to 1 for now; this limits the concurrent executing jobs to 1. In the future if you want to set-up a more advanced configuration you can configure multiple jobs to run simultaneously (for example for multiple solutions) - just make sure they use separate resources so that they don't affect each other (for example separate Servoy Installations).
  • "Jenkins URL": to the real URL that will be used by users to access the Jenkins server. (for example this will appear as part of notification emails)
  • "System Admin e-mail address": use your email address.
  • "E-mail Notification": configure this as needed. By default it will try to use the localhost SMTP server which will already be working probably on some linux machines. You can also test the configuration by sending a test email.
  • hit the "Save" button.

Step-by-step configuration for using it with Servoy

In the SVN repository we will have Servoy solutions that need to be automatically tested using import-smart-client and a solution to be automatically tested in mobile-test-client. The ANT scripts used by Jenkins to automatically export and test Servoy solutions will be in a separate project "antRunner" in the same SVN repository.

Step 1 -- Sample workspace and SVN content

Sample workspace

First we have to set-up sample SVN contents. This can be done on any computer with access to the SVN server, not necessarily on the same computer as Jenkins.

Here is the sample Servoy workspace that we will use: SoftwareFactory_Jenkins_Workspace.zip.

Unzip. Start Servoy Developer and switch workspace to the unzip location (File -> Switch Workspace).

Go to File -> Import -> General -> Existing Projects into Workspace. At "Select root directory" click the browser button then enter (it should select the workspace directory). Check all projects - you should see all (8) projects that you previously unzipped. Click finish.

You can now have a look at the sample solutions and run tests on them from developer.

Commit to your SVN repository

Install Subclipse plugin in Servoy Developer (Help -> Install New Software) if you haven't already done so.

Open Navigator view (Window -> Show view -> Other -> General -> Navigator). Select all projects and right click -> Team -> Share Project -> SVN.

For each project click on "Share project" button and add it to your SVN repository (you can use an existing SVN repository or just make a SVN test server with SVN server software such as VisualSVN). I added it to something like http://myhost:[svnServerPort]/svn/jenkinsSolutions/trunk/[project_name]. For the first project you will have to choose "create repository (connection)" -> "http://myhost:[svnServerPort]/svn/jenkinsSolutions" and folder "trunk/demo_ipAddressValidator". For the rest you will choose an existing SVN repository (the connection you just created).

After all projects are shared, select all from Navigator view, right click -> Team -> Synchronize. In the "Synchronize view" select all and right click -> Commit.

Step 2 -- Install separate Servoy Developer

We need an installation of Servoy Developer for exporting test solutions and running tests.

Download and install Servoy Developer. It's best to use a clean installation (no extra eclipse plugins) to avoid potential problems generated by other eclipse plugins (for example installing Subclipse in this developer can cause a hang as that plugin is trying to access the UI while blocking a resource - in the headless solution export environment).

Step 3 -- Configure smart client Jenkins job

Your Jenkins server should have access the SVN server you just committed to - in case you didn't use the same computer. Navigate to the Jenkins server page in your browser.

Click on New Job -> Build a free-style software project, set the Job name to "smart_client_tests" ('_' is used to avoid problems with spaces in paths where used as command line arguments - extra care is needed otherwise) and click Ok.

Under "Advanced Project Options" click the button then in "Display Name" type Smart Client Tests.

Under "Source Code Management" select Subversion. We will add the projects needed for smart client tests one by one:

  1. fill Repository URL with http://myhost:[svnServerPort]/svn/jenkinsSolutions/trunk/solution1. When you tab out of the field, if your SVN repository requires authentication - and you didn't already provide it, you will get a red error message "Unable to access ... ". Click on the "enter credential" link and add the SVN credentials that this test server is meant to use.
  2. remove the dot in "Local module directory (optional)"
  3. click on "Add more locations" and repeat the two steps above 4 times - for the other needed projects. Use the URLs for "solution2", "moduleof2", "resources" and "antRunner".

Note: you can also checkout the whole branch at once if all your projects are needed for smart-client tests. Then you will have to leave the "." in "Local module directory (optional)".

Under "Build Triggers" select "Poll SCM" and in "Schedule" field use H/3 * * * * (every 3 minutes, let Jenkins choose the minute to avoid overcrowding in the future). This will make Jenkins check for SVN changes every minute (you can increase that to decrease requests on SVN server) and if changes are found Jenkins will trigger the build. If you want a check every minute use * * * * *.

Under "Build Environment" check "Abort the build if it's stuck", then select "Absolute" - 7 minutes. This will make sure that the build ends with failure after 7 minutes if something gets stuck. This is optional and of course you need to tweak this depending on how long your tests usually take. This option is contributed to Jenkins by the "build timeout plugin".

Under "Build" click on "Add build step". Choose "Invoke Ant". Select the version you configured to auto-install at "Other things to configure" above. Click on "Advanced". In "Targets" type main_smart. In "Build file" type antRunner/jenkins_build.xml. In "Properties", expand the field (arrow down button) then type work.servoy.install.dir=[path_to_your_separate_Servoy_developer_installation] on one line and WORKSPACE=${WORKSPACE} on the second line. If you are on windows use '/' or '\\' instead of '\' in that path. For example "work.servoy.install.dir=f:/ServoyInstalls/Servoy_7.3".

Under "Post-build Actions":

  • add "Archive the artifacts" with this in "Files to archive": antRunner/jsunit_results/junit-noframes.html, antRunner/jsunit_results/smart_import_test_client_log.txt, antRunner/jsunit_results/workspace_exporter_app_server_log.txt, antRunner/jsunit_results/workspace_exporter_workspace_log.txt
  • add "Publish JUnit test result report" with "Test report XMLs" set to: antRunner/jsunit_results/TESTS-TestSuites.xml
  • add "E-mail notification" and type your email address in "Recipients" field.

Click on "Save" and go back to Jenkins dashboard. The new job you just created "Smart Client Tests" should automatically start in under 3 minute (or you can start it manually using the "play" icon next to it). It should pass.

If anything goes wrong you can click on your job's name then on the left side you see a list of builds. Click on the build that failed and you can see it's details (time/status/tests/console/...).

I also like to have "AUTO REFRESH" enabled as well (a link in Jenkins dashboard) - just to make sure the page is showing the latest status of Jenkins.

After a build finishes you should have 4 files in your build/Status/Build Artifacts - one showing the test results and 3 Servoy log files showing what happened during export.

Step 4 -- Configure mobile client Jenkins job

For mobile testing we will need Chrome browser installed (other browsers, even mobile device simulations/emulations can be used, check the help page of Servoy mobile test runner for details), a copy of SeleniumServer jar downloaded (http://docs.seleniumhq.org/download/) and a copy of Chrome selenium driver downloaded/extracted (http://code.google.com/p/chromedriver/downloads/list). The mobile test solution will automatically be deployed in Servoy Developer's bundled Tomcat server (the one at [work.servoy.install.dir]) and started using Selenium in the Chrome browser to run tests - by the mobile servoy test suite. If the tests pass, the actual mobile solution will be exported and copied to/deployed in [deploy.servoy.install.dir]'s bundled Tomcat.

Click on New Job -> Build a free-style software project, set the Job name to "mobile_client_tests" and click Ok.

Under "Advanced Project Options" click the button then in "Display Name" type Mobile Client Tests.

Under "Source Code Management" select Subversion. We will add the projects needed for mobile client tests one by one:

  1. fill Repository URL with http://myhost:[svnServerPort]/svn/jenkinsSolutions/trunk/demo_ipAddressValidatorTester. When you tab out of the field, if your SVN repository requires authentication - and you didn't already provide it, you will get a red error message "Unable to access ... ". Click on the "enter credential" link and add the SVN credentials that this test server is meant to use
  2. remove the dot in "Local module directory (optional)"
  3. click on "Add more locations" and repeat the two steps above 5 times - for the other needed projects. Use the URLs for "demo_ipAddressValidatorTester_service", "demo_ipAddressValidator", "demo_ipAddressValidator_service", "resources" and "antRunner".

Under "Build Triggers" select "Poll SCM" and in "Schedule" field use H/3 * * * * (every 3 minutes, let Jenkins choose the second to avoid overcrowding in the future). This will make Jenkins check for SVN changes every minute (you can increase that to decrease requests on SVN server) and if changes are found Jenkins will trigger the build. If you want a check every minute use * * * * *.

Under "Build Environment" check "Abort the build if it's stuck", then select "Absolute" - 10 minutes. This will make sure that the build ends with failure after 10 minutes if something gets stuck. This is optional and of course you need to tweak this depending on how long your tests usually take. This option is contributed to Jenkins by the "build timeout plugin".

Under "Build" click on "Add build step". Choose "Invoke Ant". Select the version you configured to auto-install at "Other things to configure" above. Click on "Advanced". In "Targets" type main_mobile. In "Build file" type antRunner/jenkins_build.xml. In "Properties", expand the field (arrow down button) then type:

work.servoy.install.dir=[path_to_your_separate_Servoy_developer_installation]
deploy.servoy.install.dir=[path_to_your_deployment_Servoy_developer_installation]
webdriver.chrome.driver=[path_to_chromedriver.exe_that_was_downloaded_above]
selenium.server.jar=[path_to_downloaded_selenium_server_jar]
WORKSPACE=${WORKSPACE}

If you are on windows use '/' or '\\' instead of '\' in that path. For example:

work.servoy.install.dir=f:/ServoyInstalls/Servoy_7.3
deploy.servoy.install.dir=f:/ServoyInstalls/Servoy_7.3_deployment
webdriver.chrome.driver=f:/Selenium/Drivers/Chrome/chromedriver.exe
selenium.server.jar=f:/Selenium/selenium-server-standalone-2.33.0.jar

The deployment installation of Servoy can be the one that "Install/Start Servoy Server Importer" step will use.

Under "Post-build Actions":

  • add "Archive the artifacts" with this in "Files to archive": antRunner/jsunit_results/junit-noframes.html, antRunner/jsunit_results/smart_import_test_client_log.txt, antRunner/jsunit_results/workspace_exporter_app_server_log.txt, antRunner/jsunit_results/workspace_exporter_workspace_log.txt
  • add "Publish JUnit test result report" with "Test report XMLs" set to: antRunner/jsunit_results/TESTS-TestSuites.xml
  • add "E-mail notification" and type your email address in "Recipients" field.

Click on "Save" and go back to Jenkins dashboard. The new job should automatically start in under 3 minute (or you can start it manually using the "play" icon next to it). It should export/run tests in chrome/export normal solution/copy it to deployment Servoy installation - with 2 test failures. To make the tests pass fix the regular expression as hinted by the comment in solution demo_ipAddressValidator, in the globals scope, and then commit the change to SVN.

If anything goes wrong you can click on your job's name then on the left side you see a list of builds. Click on the build that failed and you can see it's details (time/status/tests/console/...).

After a build finishes you should have 4 files in your build/Status/Build Artifacts - one showing the test results and 3 Servoy log files showing what happened while exporting/testing.

  • No labels