Using Maven+nexus+jenkins+svn+tomcat+sonar to build a continuous integration Environment (II)

Source: Internet
Author: User

Objective

Previous essay Maven+nexus+jenkins+svn+tomcat+sonar building a Continuous integration environment (i) describes the MAVEN and Nexus Environment building, and how to use MAVEN and Nexus Unified Management library files and versions, And how to upload your own module to a nexus for other modules to reference. Here's how you can use Jenkins, SVN, Tomcat, and Sonar to automate the compilation, testing, and release of your project, as well as check the code quality of your project.

Tool Jenkins

Jenkins originated from another continuous integration tool Hudson,hudson was developed and maintained by the open source community prior to Oracle's acquisition of Sun, and Oracle's acquisition of Sun declares that it has Hudson trademark rights, Later, the open source power of the development Hudson can only re-name "Jenkins" to continue to develop, the original Hudson by Oracle Continuous maintenance, but the update speed is relatively slow.

Jenkins Address: http://jenkins-ci.org/

Hudson Address: http://hudson-ci.org/

You can see Oracle's copyright logo in the lower right corner of the Hudson website. We use Jenkins here to build a continuous integration environment.

First download the jenkins,http://mirrors.jenkins-ci.org/war/from the official to choose a different version. After the download is complete, place it in a directory on the server and CD to that directory and execute:

Java-jar Jenkins.war

Jenkins has a built-in jetty container that uses 8080 ports by default, and if your 8080 is occupied, perform:

Java-jar Jenkins.war--httpport=8081

Of course you can also just put the war package into the Tomcat directory to start up, so Jenkins starts up.

Come to this interface we first do one thing: System configuration, mainly configure MAVEN and release plug-ins.

1. Go to "System Management" and "System Setup":

Add maven to configure the MAVEN installed on Linux.

Other keep the default configuration, save!

2. Go to "system Management"--"management plug-in" and "advanced" upload Plugin

When the upload is complete, Jenkins has the ability to publish Web applications to all types of tomcat containers.

Note: Deploy.hpi plug-in is I downloaded from the Internet in advance, you can also use the plug-in installation of Jenkins to complete the plug-in installation, but that relatively slow.

3, configure MAVEN on the Linux server, similar to the previous one you also need to configure MAVEN on the Linux server to connect to the nexus, and to support the release module to the Nexus.

Add between <settings><servers></servers></settings> nodes:

   1:    <server>    
   2:      <ID>snapshots</ID      
   3:      <username>deployment</username      
   4:      <password>123456</password      
   5:    </server>    
   6:      <server>    
   7:      <ID>releases</ID      
   8:      <username>deployment</username      
   9:      <password>123456</password      
  Ten:    </server>  

Add between <settings></settings> nodes:

   1:  <profiles>  
   2:          <profile>  
   3:              <ID>dev</ID>     
   4:              <repositories>  
   5:                  <repository>  
   6:                      <ID>local-nexus</ID>     
   7:                      <URL>http://192.168.0.109:8081/nexus/content/groups/public/</URL> 
   8:                      <releases>  
   9:                          <enabled>true</enabled>     
  Ten:                      </releases>  
  One:                      <snapshots>  
  :                          <enabled>true</enabled>     
  £                      </snapshots>  
  :                  </repository>  
  :              </repositories>  
  :          </profile>  
  :      </profiles>  
  :  
  :      <!--activeprofiles | List of profiles that is active for all builds. | -
  :      <activeprofiles>  
  :          <activeprofile>dev</activeprofile>     
  :      </activeprofiles>  

By completing these configurations, we can create a new project on Jenkins.

We have developed three projects in Eclipse: maven-parent (parent project for Unified Class Library version), Maven-support (backend module, support Web Project), Maven-sample (Web project, Dependent maven-support), and then add:

After the next entry, the main configuration is two addresses, SVN and MAVEN commands.

Follow the instructions for SVN username, password authentication.

For maven-parent projects, we execute the install command. Save!

Then create the Maven-support project, since the project is a back-end module that needs to be published on a Nexus server, so slightly different:

You need to execute the Deploy command to publish the project to the Nexus. In addition you'd better configure the project build to start after maven-paremt execution:

Best to save!

It's a good idea to create a maven-sample project, which is a Web project with a slightly different configuration:

Execute the Package command to package the project into a war packet. The most important thing to do next: Automatically publish the packaged war package to Tomcat:

Note the points:

1, war/ear files, be sure to fill in the relative address;

2, manager username, manager password is your installed tomcat username, password, if not please through the Tomcat configuration file Tomcat-users.xml settings.

3. The Tomcat URL is the Tomcat access address you installed.

Finally, set the build order so that it is built after the completion of the Maven-support execution:

Save!

On the Jenkins home page there are three projects we've created, and we just need to build maven-parent, because we've set the build order:

Look at the build information, you can see the build process, the project is updated from SVN, then compiled, run test cases, packaging, publishing process. The whole process was done by Jenkins,

At this point, Jenkins automates compiling, testing (writing test cases on its own), packaging, publishing, and deploying.

You can see that Tomcat has more maven-sample apps on it.

Deploy sonar

Download the sonar installation package from the http://www.sonarqube.org/official website, unzip to the system, go to the bin directory, select your system version, enter after the execution:

./sonar.sh Start

Sonar starts up, the default port is 9000, and you can modify it in the Conf/sonar.properties configuration file:

Sonar.web.port:                           8066

Installing the Sonar plugin in Jenkins

Similar to installing the Deploy plugin method, we upload the sonar plugin in System Management-plug-in management. After the installation is complete, please restart Jenkins.

Configure the Sonar plugin for Jenkins:

Enter System configuration

Configuring sonar based on your situation, I've just modified sonar's application port, so I just need to configure this and keep the default values.

To enter a specific project configuration sonar:

Select the next maven version, and leave the other default values. Save!

Then start building the project, and after the build is complete, you can see that the code check results for the project have been imported to the sonar platform, and the sonar system makes it easy to see the code quality of the project:

Sonar can check the complexity of the code, Code duplication, unit test coverage, whether there are comments, potential bugs and other code issues, for sonar project introduction, you can further explore, here only to introduce the method of Jenkins and sonar integration, can be further studied in practical work.

Summary

This article focuses on how to build Jenkins and how to use MAVEN, deploy plug-ins to package, publish your projects, and finally use Jenkins and sonar to work with code quality checks for projects. Complete the process we can find that the previous testing, packaging, publishing, code review work can be done by the manual conversion tool, so that the programmer's valuable time to focus on development. Looking back at Maven+nexus+jenkins+svn+tomcat+sonar to build a continuous integration environment (a) we may have different ideas about the story at the beginning.

Using Maven+nexus+jenkins+svn+tomcat+sonar to build a continuous integration Environment (II)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.