Skip to content

Configuring CI with Hudson

latusaki edited this page Dec 11, 2014 · 18 revisions

This page details the process of configuring CI with Hudson for KBPlus. The automation will include building KBPlus and running unit and functional tests.

Prerequisites

  • Hudson installed
  • Grails version required for KBPlus installed through GVM
  • Xvfb hudson plugin installed(and pointing to /usr/bin location, 'Manage Hudson'/'System Configurations'/'Xvfb installation')
  • Xvfb installed on system(available through apt-get install Xvfb)

Create Hudson List view for KBPlus jobs

  1. Go to Hudson home and click the + on Jobs status list view (~/newView)
  2. Type name and select List View.
  3. Use regular expresion to filter jobs, something like (KB.). will filter all the jobs starting with KB

Creating Hudson Jobs

Create Template Job

Hudson allows jobs to inherit settings. We are going to create a KB-Template which will include the repository and build timeout settings.

  • Now that we have our list view click New Job (~/view/All/newJob), typea name starting with KB and leave the default option "Build a free-style software job"
  • In the job configuration screen, under Source Code Management select git and enter "https://github.com/k-int/KBPlus.git". The .git ending is a requirement.
  • Click on 'Advanced' button (above 'Repository Browser' not on Git) and check 'Skip internal tag'.
  • Under 'Build Environment' tick 'Abort the build if it's stuck' with a reasonable timeout, also 'Fail the build'

These are the settings we are going to add for now. It will also make sense to enable email notifications from 'Post-build Actions' if that is required.

Create Build Job

Create a new job named 'KB-Build' and under 'Cascading Job' select 'KB-Template'. This will apply the settings described above.

  • Under 'Build Triggers' select Poll SCM and enter a desired interval from checking repo for changes (0 * * * will check every hour)

  • Under 'Build' click 'Add build step' and select 'Execute shell'. I have used the following code:

    cd app GRAILS_BUILD_VERSION=$(grep app.grails.version application.properties | awk -F= '{print $2}') /var/lib/hudson/.gvm/grails/${GRAILS_BUILD_VERSION}/bin/grails prod war

    Ideally we would want to switch versions using GVM. Due difficulties using GVM through hudson we are directly pointing to grails installation.

    • Another option is to use Grails Plugin, and set the grails version to be used for the job from there. See grails plugin for details.
  • Under 'Post-build Actions' select 'Build other jobs', and enter the name of the Unit tests job (eg KB-Unit_Tests)

Save the configuration and move to the creation of Unit_Test job.

Create Unit Test Job

Repeat the process for creating a new Job, and add 'KB-Template' again.

  • Under 'Build', add build step 'Execute shell', and add the following:

    cd app GRAILS_BUILD_VERSION=$(grep app.grails.version application.properties | awk -F= '{print $2}') /var/lib/hudson/.gvm/grails/${GRAILS_BUILD_VERSION}/bin/grails test-app unit:

    • Another option is to use Grails Plugin, and set the grails version to be used for the job from there. See grails plugin for details.
  • Under 'Post-build Actions' select 'Build other jobs' and type KB-Functional_tests

Create Functional Test Job

Functional tests require that we have a running instance of KBPlus. We also need the Xvfb plugin and tool working, in order to run the selenium tests in headless mode.

  • Create a new Job and select cascading job 'KB-Template'. Under 'Build Environment' select 'Start Xvfb before..', and under 'Advanced..' enter: 'Xvfb installation' - Choose the correct installation (see prerequisites) 'Xvfb specific displayname' - 99 'Timeout in seconds' - 0 'Xvfb screen' - 1024x768x24 'Xvfb display name offset' - 1 'Log Xvfb output' ticked.

We are going to use four shell steps for the functional tests.

  • First, point the Config.groovy, to look for settings at demo-config.groovy inside conf_hints:

    sed -i 's|${userHome}/.grails/|../conf_hints/dev/|g' "app/grails-app/conf/Config.groovy"

  • Next edit the demo-config to include username and password for DB:

    cd conf_hints/dev/ echo "dataSource.user='user'" >> demo-config.groovy echo "dataSource.password='pass'" >> demo-config.groovy

  • Next delete and create ES indices:

    curl -XDELETE 'http://localhost:9200/kbplustest/' curl -XPUT 'http://localhost:9200/kbplustest/'

  • Depending on your system startup, you may want to check grails version before running the tests:

    cd app GRAILS_BUILD_VERSION=$(grep app.grails.version application.properties | awk -F= '{print }') /var/lib/hudson/.gvm/grails/${GRAILS_BUILD_VERSION}/bin/grails -Dserver.port=19080 test-app functional:

    • Another option is to use Grails Plugin, and set the grails version to be used for the job from there. See grails plugin for details.

Running tests without deployed instance

Since the functional tests are initialized without a deployed KB+, the database specified at demo-config.groovy is going to be dropped (by default its looking at 'KBPlusTest' and any existing data will be lost. Therefore, make sure you are using a testing database.

Setup complete

Grails plugin allows to easily control the version of grails that will be used for given jobs. Install it as any plugin. Then from Hudson 'Configure System' menu, find the 'Grails' section, and use 'Add grails' to add installations. For each grails version, point it to the .gvm installation directory. GVM is a great and simple tool for installing and changing different grails versions on the same system. For more information check gvm website.

Clone this wiki locally