This DevOps Tutorial is Part 4 of my series on Java Project Versioning. Check out the other articles:
- DevOps Tutorial (Part 1): Introduction to Project Versioning with Maven
- DevOps Tutorial (Part 2): Use Maven Release Plugin to Manage Versions
- DevOps Tutorial (Part 3): Artifact Management
- DevOps Tutorial (Part 5): Parallel Deployment
At this point in time I assume you have Jenkins installed and ready to use. If this is not the case you can follow Jenkins Tutorial – Install Jenkins in order to get everything setup.
For those of you who are not familiar with Continuous Integration, the idea is fully build and test every time a change to the source code is pushed to the Source Code Management (SCM) server. This allows for very early detection of integration problems, and defects.
Let us start by making Jenkins check out our source code, and build it using Maven.
Go to the web interface for your Jenkins install. Mine is at http://quartz:8080/jenkins/. You should see the following in the middle of the page. Click the “create new jobs” link.
Provide “SampleWebApp123” as the item name and select “Maven Project”.
Now we need to setup the connection between Jenkins and Git, however Jenkins does not support Git out of the box so we are going to install a plugin. Go back to the Jenkins homepage http://quartz:8080/jenkins/ and click on Manage Jenkins.
Select Manage Plugins.
Click on Available and search for “Git”.
Scroll down to find the “Git Plugin”, check the checkbox and click “Install without restart”.
Go back to the Jenkins Homepage http://quartz:8080/jenkins and click on the name of your project.
Click configure on the left side.
At this point in the DevOps Tutorial you need to have git and maven installed on your development server. If they are not installed, installation is as simple as:
$ sudo yum install git
$ sudo yum install maven
Fill in the appropriate values in the “Source Code Management” portion of the configuration, and click save. If the repository URL is on the same machine, and the hostname is not set by DNS, then you might have to add your hostname to the first line of the file /etc/hosts file such as “127.0.0.1 localhost localhost.localdomain quartz”
It is best to use the http access to your git repository, setting up ssh access requires configuring your keys which is beyond the scope of this article.
Scroll to the maven configuration section and fill out as this shows, or as matches your system, and save the configuration.
You can now perform a build of your project by returning to the Jenkins homepage and clicking the “Schedule a build” icon as shown below.
Next we need to install the Maven Release Plug-in Plug-in. Install this plug-in the same way the Git plugin was installed.
In order to save the Git and Nexus credentials, we need to add the Config File Provider Plugin the same way the Git and Maven Release Plug-ins were installed. Then go to “Manage Jenkins” -> “Managed files” -> “Add a new Config” and select “Maven settings.xml”.
Add credentials for Git and Nexus as shown below.
Now that the credentials are stored in the config file, configure the Jenkins job to use this file. Go to the “Build Environment” section and check the “Provide Configuration files” box and select the file you just created.
Now you can use Jenkins to perform a release and store it in Nexus. Click on “Perform Maven Release” in the job menu.
Now you can enter the version number you wish to release.
At this point in the DevOps Tutorial you have a complete build pipeline to produce consistent releases. Each commit will be built, tested, and stored in Nexus.