Friday, May 06, 2011

Grails Infinitely Prompts During Jenkins Build

I've mentioned before how I'm using CloudBees RUN@cloud as my hosting solution for Scripty Note... well right alongside that I'm using their DEV@cloud Jenkins CI environment. I have a decent amount of experience with Continuous Integration environments (Hudson, Jenkins... even Cruise Control way back when). I even use and maintain a Jenkins build machine every day at MagnetStreet. So I definitely know my way around Jenkins.

That said, I was recently at a loss when I added the MySQL Connector/J grails plugin to the Scripty Note project. Everything worked great on my own machine, but when Jenkins picked it up, I was in for some excitement. The build started at about 10pm that night (which I was not monitoring) and when I checked build status the next morning, lo and behold, all of my DEV@cloud build minutes had been used up and I had received an email from someone at CloudBees saying they had stopped my build when they noticed my EBS volume had filled up because of my build log. The build had been running in an infinite loop, prompting in the log:

"Overwrite existing DataSource.groovy? (y, Y, n, N)"

Now, I had actually appreciated that prompt when I first added that plugin to the project. It had helped me upgrade the DataSource.groovy to use MySQL without hardly needing to think about it. But prompting in the build is a different story. Now as some of you probably know, the Grails plugin for Jenkins passes the --non-interactive flag through to grails on the upgrade step. However, this plugin doesn't actually get installed on the upgrade step (even if it did, the plugin ignores that flag). It actually gets installed during the test-app or run-app stage. Also, Jenkins automatically passes null through to any user prompts during the build, which that plugin interprets essentially as a /r (causing the re-prompt). So the situation was looking pretty dire.

But then I took a look at the post-install gant script for that MySQL Connector/J plugin. Turns out that it checks for a very specific property before prompting for input: "overwrite.datasource".
Jenkins Grails Configuration Example

And that's the key to the problem. So, in order to get your build to bypass that prompt, simply pass

"overwrite.datasource=false"

through in the Grails build properties. That should take care of any prompts and let your Jenkins build hum along quite happily. It seems odd that this parameter is so completely undocumented. And furthermore, that it is so hard to find other people who have run into this problem. Maybe it's because there's a very obvious solution to this that we completely missed :). In any case, I'm just glad that the plugin's source code was available for us to dig into.

One side note: after explaining the situation to CloudBees, they quickly reimbursed my minutes back to me without any hassle. That coupled with how they had monitored my build for oddities, shows how much promise this company has as a PaaS. They've been really great to work with so far.

2 comments:

Anonymous said...

Shouldn't the grails jenkins plugin be fixed to pass the non-interactive argument to the right places?

Unknown said...

It would seem like it's more of a problem with the MySQL Connector Plugin. Looking at the source code, it looks like the Connector Plugin would've ignored the non-interactive flag anyway.