Use Maven+Nexus+Jenkins+Svn+Tomcat+Sonar to build a continuous integration environment (2)

I. Introduction

The last essay Maven+Nexus+Jenkins+Svn+Tomcat+Sonar to build a continuous integration environment (1) introduce the environment of maven and nexus, how to use maven and nexus to manage library files and versions, and how to upload your own modules Go to nexus private server for reference by other modules. The following will mainly introduce how to use Jenkins, SVN, Tomcat and Sonar to complete the automated compilation, testing and release of the project, and to check the code quality of the project.

What are you waiting for? I recommend my linuxC/C++ language exchange group : [ 1106675687 ] I have compiled some learning books and video materials that I think are better to share in the group files, and you can add them if you need them!

Second, the weapon Jenkins

Jenkins originated from another continuous integration tool Hudson. Hudson was developed and maintained by the open source community before Oracle acquired Sun. After Oracle acquired Sun, it declared that it had the right to use Hudson's trademark. Later, the open source force that developed Hudson could only rename it." Jenkins" to continue development, the original Hudson is maintained by Oracle, but the update speed is relatively slow.

jenkins address: http://jenkins-ci.org/

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

You can see the copyright logo of oracle in the lower right corner of Hudson's official website. Here we use Jenkins to build a continuous integration environment.

First download jenkins from the official website, http://mirrors.jenkins-ci.org/war/ can choose different versions. After the download is complete, place it in a directory of the server, cd to that directory, and execute:

java -jar jenkins.war

Jenkins has a built-in jetty container, which uses port 8080 by default. If your 8080 is occupied, please execute:

java -jar jenkins.war --httpPort=8081

Of course, you can also directly put the war package into the tomcat directory and start it, so that jenkins will start.
Insert picture description here
When we come to this interface, we do one thing first: system configuration, mainly configuring maven and publishing plugins.

1. Enter "System Management" -> "System Settings":

Add maven and configure maven installed on linux.
Insert picture description here
Others keep the default configuration, save!

2.
Insert picture description here
Go to "System Management" -> "Management Plug-ins" -> "Advanced" upload plugins . After uploading is complete, jenkins has the ability to publish web applications to various tomcat containers.

Note: I downloaded the deploy.hpi plug-in in advance from the Internet. You can also use the plug-in installation function that comes with jenkins to complete the plug-in installation, but that is slower.

3. Configure maven on the linux server. Similar to the previous article, you also need to configure maven on the linux server to connect it to the nexus private server and support the release of modules to nexus.

Add between nodes:

<server>  
         <id>snapshots</id>  
         <username>deployment</username>  
        <password>123456</password>  
     </server>  
     <server>  
      <id>releases</id>  
         <username>deployment</username>  
         <password>123456</password>  
      </server>

Add between 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>
  10:                      </releases>
  11:                      <snapshots>
  12:                          <enabled>true</enabled>
  13:                      </snapshots>
  14:                  </repository>
  15:              </repositories>
  16:          </profile>
  17:      </profiles>
  18:   
  19:      <!-- activeProfiles | List of profiles that are active for all builds. | -->
  20:      <activeProfiles>
  21:          <activeProfile>dev</activeProfile>
  22:      </activeProfiles>

After completing these configurations, we can create a new project on jenkins.

We developed three projects in eclipse in advance: maven-parent (parent project, used for unified library version), maven-support (back-end module, support web project), maven-sample (web project, dependent on maven-support ), add them one by one:
Insert picture description here
Insert picture description here
follow the prompts to perform SVN user name and password authentication.
Insert picture description here
For the maven-parent project, we can execute the install command. save!

Then create the maven-support project. Since the project is a back-end module and needs to be published to the nexus server, it is slightly different:
Insert picture description here
here you need to execute the deploy command to publish the project to nexus. In addition, you'd better configure the project to start after maven-paremt is executed:
Insert picture description here
it is best to save!

It is best to create a maven-sample project, which is a web project, and the configuration is slightly different:
Insert picture description here
execute the package command to package the project into a war package. The most important thing is to do the following: automatically publish the packaged war package to tomcat:
Insert picture description here
Note a few points:

  • 1. For WAR/EAR files, the relative address must be filled in;
  • 2. Manager username and Manager
    password are the user name and password of the tomcat you installed. If not, please set it through the tomcat configuration file tomcat-users.xml.
  • 3. The tomcat url is the tomcat access address you installed.

Finally, set the build order and let it build after the maven-support execution is completed:

Insert picture description here
Save!

There are three projects we created on the jenkins homepage. We only need to build maven-parent, because we set the build order:
Insert picture description here
check the build information, you can see the build process, the project is updated from svn first, Then compile, run test cases, package, and publish. The whole process is completed by jenkins,
Insert picture description here
so far jenkins has realized automatic compilation, testing (writing test cases by yourself), package release, and deployment.
Insert picture description here
You can see that there are more maven-sample applications on tomcat.
Insert picture description here
What are you waiting for? I recommend my linuxC/C++ language exchange group : [ 1106675687 ] I have compiled some learning books and video materials that I think are better to share in the group files, and you can add them if you need them!

Three, deploy Sonar

Download the sonar installation package from http://www.sonarqube.org/ official website, unzip it to the system directory, enter the bin directory, select your system version, and execute:
./sonar.sh start
sonar and it will start , The default port is 9000, you can also modify it in the conf/sonar.properties configuration file:

sonar.web.port: 8066
Insert picture description here
install the sonar plugin in Jenkins

Similar to the method of installing the deploy plugin, we upload the sonar plugin in the system management-plugin management. After the installation is complete, please restart jenkins.
Insert picture description here
Configure the sonar plugin for jenkins:

Enter the system configuration
Insert picture description here
Configure sonar according to your situation. I have only modified the application port of sonar here, so only need to configure this, and keep the default values ​​for others.

Enter the specific project configuration sonar:
Insert picture description here
Insert picture description here
select the maven version, and keep the default values ​​for others. save!

Then start to build the project. After the build is completed, you can see that the code check result of the project has been imported to the sonar platform, and the code quality of the project can be easily viewed through the sonar system:

Sonar can check the complexity of the code, code duplication, unit test coverage, whether there are comments, potential bugs and other code issues. For the introduction of sonar's project, you can further study and explore. Here, only the method of integrating jenkins and sonar is introduced. Further research during actual work.
Insert picture description here
Insert picture description here

Four, summary

This article mainly introduces how to build jenkins and how to use maven and deploy plugins to package and publish your project. Finally, use jenkins and sonar to check the code quality of the project. After completing the entire process, we can find that the previous work of testing, packaging, publishing, and code inspection can be completed by manual conversion tools, allowing programmers' precious time to focus on development. Looking back at the story at the beginning of Maven+Nexus+Jenkins+Svn+Tomcat+Sonar to build a continuous integration environment (1) , we may have different ideas.

What are you waiting for? I recommend my linuxC/C++ language exchange group : [ 1106675687 ] I have compiled some learning books and video materials that I think are better to share in the group files, and you can add them if you need them!

Guess you like

Origin blog.csdn.net/m0_50662680/article/details/112787635