Friday, December 30, 2011

Check element existance in Geb

In Geb, if you need to check if some element does exists on page or not the best looking way to do it is method isPresent(), so it can be called like:

!notNeededLink.present
otherLink.present

Of course if you plan to check non-existing elements like this they need to be defined as not required and with wait - false. For example:

notNeededLink(to: SomePage, required:false, wait: false) {$('a', text:'Some')}

Tuesday, December 20, 2011

Too many idle database connections with Tomcat

I recently had problem when there were too many open database connections in Tomcat. Everything was right, but number is far more then is defined in Tomcat resources.
After some investigation, I have found that problem was that datasources were defined in wrong place - conf/context.xml, and when they are defined there, they are picked for every Web application that is defined in this Tomcat instance (including management and utility), therefore you will have all your connections multiplied by number of applications you have.
Fortunately, it is easy to fix by defining resources under conf/Catalina/localhost/ROOT.xml (ROOT if application is defined under root, otherwise, name of your application), in which case, resources will be provided only for specified application.

Tuesday, December 6, 2011

Passing upstream parameters to downstream builds in Jenkins

Jenkins has cool Pipeline plugin, which helps to create build pipelines, that for example, can organize and visualize deployment process. Plugin is very cool and looks great, but lacks few basic features, like passing generated parameters or variables from upstream builds to downstream.
For example, I wanted to pass SVN revision number into downstream builds.
Fortunately it is easy to do it with little hacking. Here is what I did.
  1. Add Groovy plugin.
  2. Add new build step Execute system Groovy script, now it is possible to hook into Jenkins internals.
  3. Then just add Groovy script there:
import hudson.model.*
def thr = Thread.currentThread()
def build = thr?.executable
build.addAction(new ParametersAction(new StringParameterValue('SVN_UPSTREAM', build.getEnvVars()['SVN_REVISION'])))


What this script does it just creates new parameter and adds SVN_REVISION from environment variables there. And pipeline can pass parameters with this mechanism to downstream builds (all of them).
Easy!