June 17, 2013 by shashikant
In this blog I am going to share how to configure jenkins with grails on Ubuntu.
Install jenkins via command:
wget http://pkg.jenkins-ci.org/debian/binary/jenkins_1.518_all.deb //download jenkins.deb file.
I assume that Java,Grails and latest version of Git is installed on your Machine if not please install them for further configuration.
Install daemon via command: sudo apt-get install daemon
Install jenkins via command: sudo dpkg -i filename.deb
The default port of jenkins is:8080 .If you want to change the port number go to etc/default directory and open jenkins file in editor and change the port no.
Step 4 :
Now start jenkins via command : sudo service jenkins start
you will see on terminal
Starting Jenkins Continuous Integration Server jenkins [ OK ]
after that, type in browser http://localhost:8888 //8888 is my default port for jenkins
you will see the jenkins dashbord on browser
Now click on manage jenkins and install required plugin
Here is the list of required plugin for grails.
1.Ant plugin 2.ChuckNorris plugin 3.Crediantials Plugin 4.External Monitor Job Type Plugin 5.Git Hub Api Plugin 6.Git hub plugin 7.java doc plugin 8.jenkins cvs plugin 9.jenkins git client plugin 10.jenkins git plugin 11.jenkins grails plugin 12.Jenkins mailer plugin 13.jenkins SSH plugin 14.Jenkins SSH slaves plugin 15.jenkins subversion plugin 16.Jenkins translation assistance plugin 17.Ldap plugin 18.Maven Integration Plugin 19.PAM Authentication plugin 20.Publish Over SSH plugin 21. SSH Crediantial plugin.
Step 6 :
After successfull installation of plugins:
create a new job like this:
create a Job name
checked the radio button of Build a free-style software project
Step 7 :
Now checked the radio button for Git
enter the uri of your git repeository.
If you will see the error like
Failed to connect to repository : Command "git ls-remote -h email@example.com HEAD" returned status code 128:
stderr: fatal: 'firstname.lastname@example.org' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
You have to do some more configuration:
Go to to the terminal
Run this command :sudo visudo
Add jenkins ALL=(ALL:ALL) ALL in this file where sudo previlage is defined.and close the file.
login as jenkins user via command :sudo su jenkins
Create a .ssh directory in the jenkins home directory.
create the public private key pair like this.
Generating SSH Keys:
Step 1: Check for SSH keys
First, we need to check for existing ssh keys on your computer. Open up Terminal and run:
cd ~/.ssh # Checks to see if there is a directory named ".ssh" in your user directory
If it says "No such file or directory" go to step 2. Otherwise, you already have an existing keypair, and you can skip to step 3.
Step 2: Generate a new SSH key
To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.
ssh-keygen -t rsa -C "email@example.com" # Creates a new ssh key, using the provided email as a label # Generating public/private rsa key pair. # Enter file in which to save the key (/home/you/.ssh/id_rsa):
Now you need to enter a passphrase or file.press enter without to write any thing.
Which should give you something like this:
Your identification has been saved in /home/you/.ssh/id_rsa. # Your public key has been saved in /home/you/.ssh/id_rsa.pub. # The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db firstname.lastname@example.org
Step 3: Add your SSH key to GitHub
Go to your Account Settings
Click "SSH Keys" in the left sidebar
Click "Add SSH
key"Paste your key into the "Key" field
Click "Add key"
Confirm the action by entering your GitHub password
Step 4: Test everything out
To make sure everything is working you'll now SSH to GitHub. When you do this, you will be asked to authenticate this action using your password, which for this purpose is the passphrase you created earlier. Don't change the email@example.com part. That's supposed to be there.
Run the command on terminal:
ssh -T firstname.lastname@example.org # Attempts to ssh to github
You may see this warning:
The authenticity of host 'github.com (126.96.36.199)' can't be established. # RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. # Are you sure you want to continue connecting (yes/no)?
Don't worry, this is supposed to happen. Verify that the fingerprint matches the one here and type "yes"
Hi username! You've successfully authenticated, but GitHub does not # provide shell access.
If that username is correct, you've successfully set up your SSH key. Don't worry about the shell access thing, you don't want that anyway.
Now go to the step 7 again
hope this time you will be successfully connected to your git repository.
Now you have to configure Jenkins Envinment.
go to Manage jenkins ->configure system
Click on Grails Installation.
Add name of your grails version.(optional)
Add path of your grails SDK to Install directory field.
Click on JDK Installation.
Add name of your Java version.(optional).
Add path of your JDK to Install directory field.
now go to Git Plugin
Add your git user name to Global Config user.name Value field
Add your email id to Global Config user.email Value field.
Click on save button. Now your jenkins is configured for your grails environment.
Now click on your project->configure
checked the check box Pull SCM under Build Triggers
Enter H/5 * * * * in the field Schedule
Click on Add build step->Execute Shell.
Add your mechine specific setting in Command field to stop the server.
sudo sh /home/shashikant/apache-tomcat-7.0.40/bin/shutdown.sh
Click on Add build step->Build with grails.
change grails installation Default to your grails version.
Add "war target/ROOT.war" to target field
Again Click on Add build step->Execute Shell.
Add your mechine specific setting in Command field.
For my machine its :
sudo rm -rf /home/shashikant/apache-tomcat-7.0.40/webapps/ROOT*
sudo mv /var/lib/jenkins/jobs/OodlesVid/workspace/target/ROOT.war /home/shashikant/apache-tomcat-7.0.40/webapps/
sudo sh /home/shashikant/apache-tomcat-7.0.40/bin/startup.sh
Click on save .Now your jenkins is Ready to use.