Notice: This resource is no longer being actively maintained and as a result some information may be out of date or inaccurate. Please see for technical instructions or for support related concerns.
DEV@cloud » Build and Deploy a Grails application

Build and Deploy a Grails application

Last modified by Robert Wallström on 2011/12/05 20:09

This article was contributed by courtesy of Stephen Fisher As a CloudBees addict, you're welcome to contribute content to our wiki, please contact

A 101 on how to set-up CI for a Grails applications using Cloudbees

In this article I explain how I was able to set-up a Git repository on, populate it with a sample Grails application and then set-up Jenkins on to poll the GitHub repository for changes, build the application and deploy the application to the Cloud on CloudBees. After reading this article you should be able to repeat the process in less  than 30 minutes yourself.


I assume that you have:

  • Downloaded Grails and have a JVM installed from
  • Are comfortable using a Unix like terminal shell (I am using Mac Os. I could have used Windows but at home I prefer to use my macbook)
1. Setup Master Git Repository 

For this tutorial, I have used a GitHub hosted repository. You can also use CloudBees forge or whatever repository hosting service you like.

Click on the Set up Git tab and download and install git for your machine if not already present. This page explains how to get up your Github user name and email address in your local git global configuration file and how to set-up and store your ssh key.

If you don't have one already, you will create a local ssh key for GitHub access using ssh-keygen, as follows:

Follow the instruction on how to configure git to be able to access your newly created GitHub repository as follows:

  • If you haven't already register for an account on
  • Next create a repository on GitHub. I called my first one grailstest so this can later be accessed using the access string:<your-github-id>/<your_repo_name>.git (you can see my name on Github is seahope1 and the access string is shown clearly.

Next from your Github Account Settings tab access the SSH Public Keys tab and store your local ssh public key for your machine which you need to create as explained on the Set up Git tab. The default public key to store on GitHub will be stored locally in ~/.ssh/

You will also need to add the CloudBees public key which you can find within the Jenkins job which you will create later. I will come back to this.

2. Create a local working git repository

In a local terminal window follow the instruction you get when you click on your empty repository on Github. I have added the 'grails add first' command to create a basic grails application to provide files to add to the repository:

git init
grails create-app first
git add first
git commit -m 'first commit'
git remote add origin<your-github-id>/grailstest.git
git push -u origin master

This will upload the default Grails application to your repository. You will be asked for your GitHub usename (not email address) and password when use use git push.

3. Set-up for Continuous Integration and deployment
  • If you haven't already, sign-up for an acount at
  • Make sure you subscribe for DEV@cloud & RUN@cloud services. I selected the free options.

  • From the Jenkins page select Manage Jenkins -> Manage Plugins and enable the Git plugin. Ensure you select Install when you will be asked to restart Jenkins.
  • You also need to enable grails and github support are listed under the Available tab.

  • Again, you will need to restart Jenkins for these changes to take effect, which may take a few minutes.
  • From the Home screen -> Applications -> Add new application and call it: first grails

  • From Jenkins screen create a New Job & select Build a free-style software project and name the job first.

Setup the following fields as follows:

  • Project name: first
  • GitHub project:<your-github-id>/<your-repo>.git
  • Source Code management -> Git repositories selected. URL of repository:<your-github-id>/<your-repo>.git
  • Branches to build Branch Specifier: **

A while ago I mentioned the Cloudbees Public Key. This is located under the heading Cloudbees DEV@Cloud Authorization (towards the top of the screen). This is the key that needs to be entered in GitHub as described above as another SSH Public key. Once this key is added to GitHub for your account Jenkins will be authorised to access  the repository to get the source to build.

  • Build Triggers -> select Poll SCM and enter the pattern: * * * * *. 
  • Build Add Build Step and select Grails

  • Build -> Build with Grails -> Grails Installation: Grails 1.3.7 (or your version)
  • Targets: "war target/first.war"
  • Project base directory: first

  • Post-build actions -> Archive the artifacts Files to archive: first/target/first.war
  • Deploy to Cloudbees selected, Cloudbees site:<your-Cloudbees-id> (auto-populated)
  • Application Id: <your-Cloudbees-id>/firstgrails
You can safely ignore the error message as it is just telling you that the grails target has not been created through a build yet.

Save the job and select Build Now to test the job. At this point you will be asked to validate your account by clicking on a URL. The page displayed will ask for a telephone number where the automated call back service will provide a pin number which you need to enter to complete the validation process. Once you have successfully validated you will be able to run the job.

The Build History window will show progress.  If you click on the build number (hopefully with a blue sucessful icon showing) you can use Console Output [raw] to check to see what happened and if successful you can run the deployed application by clicking the link: http://firstgrails.<your-cloudbees-id> to access the running sample application. You can find the link from the Application screen:

4. Make a change to the application and prove CI & CD works

In the Grails application change change the file: grailstest/first/grails-app/view/index.gsp e.g. change the text "Welcome to Grails" to "Welcome you to Grails" in both places. Then execute the commands:

git add index.gsp
git commit -m 'simple change to index.gsp'
git push -u origin master

You will notice on the Cloudbees Jenkins dashboard that after about one minute another build will be executed and once it completes successfully the application deployed will show the change.

Next Steps
  • You will notice that I haven’t tried to run the Grails tests and this step would have to be added before the application is deployed.
  • I have not had a chance to explore using the Cloudbees SQL database.
  • I have not explored how Grails plug-ins work with Grails on Cloudbees
Created by Nicolas De Loof on 2011/09/19 11:32