Continuous Integration with Grails and Jenkins

This article addresses how to create a Grails build with Jenkins and the Grails Wrapper.

WARNING: Using the Grails Wrapper to build a project is significantly slower than using a pre-installed Grails SDK as described in the How to declare a Grails SDK in Jenkins. Details on the Grails Wrapper are available at The Grails Framework - Reference Documentation - Grails Wrapper.

Setup

1. Click on Builds

01-goto-builds.png

2. Click on Manage Jenkins

02-goto-manage-jenkins.png

3. Click on Manage Plugins

03-goto-manage-plugins.png

4. Ensure that the Grails plugin is enabled

04-installed-plugins.png

…​

05-installed-plugin-grails.png

5. Create a Free Style Job

10-create-free-style-job.png

6. Add a "Build With Grails" step using Grail Wrapper

11-build-with-grails.png

12-build-with-grails.png

Warning, using the "Grails Wrapper" to build the application requires the prior installation of this Wrapper (see Grails Documentation > The Wrapper).

7. Add a post build action "Deploy Application"

13-deploy-application.png

How to declare a Grails SDK in Jenkins

If you don’t use the Grails Wapper, you will need to declare a Grails SDK in your Jenkins configuration.

1. Click on "Manage Jenkins"

06-goto-manage-jenkins.png

2. Click on "Configure System"

07-goto-configure-system.png

3. Scroll down to Grails and click on "Grails installations…​"

08-add-grails-sdk.png

4. Declare the Grails SDK with the needed version

09-declare-grails-sdk.png

FAQ

My build fails with IOException: Cannot run program "grails"
 [grails-petclinic] $ grails clean --non-interactive
 FATAL: command execution failed
 java.io.IOException: Cannot run program "grails" (in directory "/scratch/jenkins/workspace/grails-petclinic"): error=2, No such file or directory
  at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
  ...
 Caused by: java.io.IOException: error=2, No such file or directory
  at java.lang.UNIXProcess.forkAndExec(Native Method)
  ...
 Build step 'Build With Grails' marked build as failure
 Finished: FAILURE

You probably configured the Grails build to not use the Grails Wrapper and the local "Grails installation" has a problem or there is no local Grails installation.

faq-02-grails-build-without-wrapper.png

faq-01-grails-build-select-sdk.png

Please verify that the Grails SDK you need for your job is properly configured at the Jenkins global configuration level. See How to declare a Grails SDK in Jenkins.

Special Thanks

Special thanks to Aurélien Maury from Xebia for his help!