Continuous Integration in the Cloud, Part II: Jenkins
We have already provided you with the tutorial on how to work with Hudson in Jelastic. You probably know that Hudson and Jenkins are built on the same base tools but these are different projects at the same time. So we decided to prepare one more detailed instruction for Jenkins CI tool fans. But at first we have to understand what Jenkins is and the main differences between Jenkins and Hudson.
Jenkins is the application that monitors executions of repeated jobs, such as building a software project or jobs run by cron. It focuses on the following two jobs:
- Building/testing software projects continuously, Jenkins provides an easy-to-use continuous integration system, making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. The automated continuous build increases the productivity.
- Monitoring executions of externally-run jobs, such as cron jobs and procmail jobs, even those that are run on a remote machine. For example, with cron, you receive only regular e-mails that capture the output, and it is up to you to look at them diligently and notice when it broke. Jenkins keeps those outputs and makes it easy for you to notice when something is wrong.
Jenkins is a new Hudson. One of the unique features of Jenkins is weekly schedule of releases. New features, new plugins (about 350 plugins, here is a list) and bug fixes come out weekly, and the turn-around time for bug fixes can be very short indeed. If you prefer more stability, there are always a stable release approximately every 3 months.
Let’s get started now!
Create an environment
1. Go to jelastic.com and sign up if you haven’t done so yet, or log in with your Jelastic credentials by clicking the Sign In link on the page.
2. While in Jelastic dashboard, click the Create environment button at the top left:
3. In the Environment Topology dialog, pick your application server (for example, Tomcat 6). Then type your environment name, for example, jenkins.
Wait just a minute for your environment to be created.
Upload a Java package
1. Go to jenkins-ci.org and download the latest version of Jenkins.war file.
2. Go back to Jelastic dashboard, click the Upload button in middle left of the screen, browse the WAR package and click the Upload button.
3. Once the upload is over, click the Deploy to… button next to the package in the Deployment manager, and pick your environment as the target.
4. You can then optionally create a context for the deployment (you would do that if you want to run multiple applications on one server – each would get a subURL based on the context you specify – e.g. myenvironment.jelastic.com/mycontext), just leave it as ROOT if you don’t need subURLs.
5. Once the deployment is finished you can click the Open in browser button for the environment.
Now you can use Jenkins with all its functionality.
1. Modify configuration files: settings.xml and pom.xml of your project to include the Maven plugin for Jelastic. This allows you to deploy your application to the Cloud, automatically.
- Add the Profile tag to your settings.xml file as shown below:
<jelastic.username>[insert your Jelastic username]</jelastic.username>
<jelastic.password>[insert your Jelastic password]</jelastic.password>
- Add Plugin Repository to your project pom.xml :
- Add to your pom.xml file the dependency section:
<!-- ... -->
<context><!-- insert your context path or ROOT for default --></context>
<environment><!-- insert your environment name --></environment>
<api_hoster><!-- default value "api.jelastic.com" --></api_hoster>
<!-- ... -->
Insert in <api_hoster> tag API depending on your hoster. You can find the necessary API in the Hosters Info document.
2. Navigate to the Manage Jenkins tab, click on Configure system and ask Jenkins to install Maven automatically. Specify Maven’s name and choose its version.
Don’t forget to save the changes!
3. Create a New Job. Enter job name, select Build a Maven 2/3 project and click ok.
4. On the job Configuration page, in the Source Code Management section, choose Subversion and enter your repository URL.
Then select Poll SCM in the Build Triggers section and set the time period for polling. Jenkins will poll your system regularly for changes, e.g. every minute.
In the Build section specify the Root pom (pom.xml). Then type clean install jelastic:deploy in the Goals and option field to deploy your application automatically.
Click on Save at the bottom of the page.
5. Click on the Build Now in the left sidebar. After that click on the progress bar to open the console view and you can follow the progress.
In just a few minutes, your project will be successfully built. Once the build process has been finished, you can navigate to your job to ensure that the war file has been created.
6. Go to the Jelastic platform dashboard and you’ll see that you app has been deployed to the context you specified in pom.xml.
7. Now, if you make some corrections or changes to your project, after commit, Jenkins indicates those changes and automatically builds and deploys the updated application to Jelastic.
Here is also a video version of the deployment procedure:
That’s all for today! Please let us know what tool you prefer to use Jenkins or Hudson in the comments to this post.