About quality Improvement during Java development-2 automation

Source: Internet
Author: User
Tags postgresql module hosting sites ssh access

Developers write code in the process of implementing automatic Code view, the editor will prompt the coding specification error, and give the correct instance, write the code only need to submit to the SVN library, and then start the automated build (configurable code submitted after SVN automatically triggered), the test environment in the project immediately and the current SVN library consistent. Bid farewell to call the Code review meeting (or just the business process), bid farewell to the manual compilation package, install.

----------------------------------------------------------------------------------Copy from Word file, do not bother to get pictures, so no diagram.

Chapter I. Jenkins Configuration

Jenkins is a widely used Visual Web tool for continuous building, and the continuous build is more straightforward, which is the "automation" of various projects to compile, package, and distribute the deployment. Jenkins is well-supported in all languages (e.g. Java, C #, PHP, Python, and almost all languages), and is fully compatible with various third-party build tools such as Ant, Maven, Gradle, and seamlessly integrates with SVN and git. Direct integration is also supported directly with well-known source-code hosting sites, such as GitHub and BitBucket.

Jenkins itself is developed in the Java language, so the machine that installs Jenkins must have at least JDK, and it is recommended that GIT/SVN, Ant/maven/gradle and other tools are installed together to facilitate integration with these build tools.

1.1 Installing Jenkins

Can be directly on the official Jenkins website: https://jenkins.io/index.html

Download Jenkins file Jenkins.war file

There are two ways to start.

First make sure the JDK is installed in the system, preferably jdk1.8, and configure the environment variables.

The first method of startup, switch to the directory where the Jenkins.war is stored, enter the following command:

$ Java-jar Jenkins.war

Then enter Http://localhost:8080,localhost in the browser to either the native IP or the computer name. We can open Jenkins.

The second method is to open with jetty

Put the Jenkins.war file in the WebApps directory under Jetty, and when you start Jenkins, enter it on the address bar

Http://localhost:8080/jenkins will be able to access

1.2 Configuring Jenkins

Since the Jenkins configuration is very informative on the web, only the key operations are listed here:

1, Login Jenkins, select "System Management, plug-in management, optional plug-in", install the following plug-ins;

a) Mail plugin: email Extension Plugin

b) Maven plugin: Maven Integration Plugin

c) SVN plugin: svn Publisher plugin

d) SSH plugin: ssh plugin/publish over SSH

Just install the need to wait a few minutes to plug-in list, if the installation fails to see the reason for failure, generally because there is a dependency plug-in is not installed (in the plug-in management will automatically put the dependency plug-in installed together), just install the hint plug-in, and sometimes because the network needs to install several times to mount.

2, complete the plug-in installation, select "System Management, System settings", configure mail and related server information can be

Remote directory is the directory that specifies SSH access, and it is important to verify that the user has permissions first.

3, complete the system configuration, select "System Management, Global Tool Configuration", configure the JDK and Maven

JDK and Maven need to be pre-installed before specifying the installation directory here.

1.3 Create Job

1. Create a project

A) sign in to Jenkins, select "New", enter the project name and select "Create a free-style software project"

b) Enter the job above and select "Configure" to enter the configuration interface

c) Configure "Discard old Build"

This is mainly to configure the number of retention of build tasks

d) Configure the source control and build triggers

If the company's SVN repository is encrypted, select "None" here and download the code into the "/home/xxx/.jenkins/workspace/job name" directory later in the procedure.

Choose "Build periodically" to start the build task on a timed basis, such as starting the build 1 o'clock in the morning every day, and "Poll SCM" is the time to check the source database submission to start the build, because there is no use of source management, so this option is not used. If there is source control, the configuration detects code changes based on the specified frequency, triggering the build.

E) Configure "Build Environment"

I. If the company SVN is encrypted and the SVN plugin is not available, download the code to the server before building, select "Send files or execute commands over SSH before the build starts" to specify the build server, Call the script that downloaded the code sh buildsvn.sh jobID Svnurl For example: "Sh/home/xxx/jenkins/build/buildsvn.sh JobID svnurl".

II. After the completion of the code download, you can choose "add Transfer Set" plus one, to the installation server to perform pre-installation data cleanup operations.

III. After completing the pre-operation, you can configure the operation after the package has been completed, select "Send files or execute commands over SSH after the build runs" is the operation after the package is finished, because the project release/Transfer test mode is hit After the package, send an email notification to the configuration administrator to the package directory to get packages, and then configure the administrator based on the SVN version number in the package to score branches, so this needs to do a soft package add SVN version number processing

Iv. once the package has been processed, the package can be uploaded to the installation server for installation, where cluster installation is supported, and how many clusters need only choose to add multiple "add Transfer Set".

Automatic installation of the first automatic installation script, here is the decompression, call setup.sh script

f) Finally, configure "build" and "post-build operations"

Configure MAVEN compilation, packaging tools, mail according to the actual situation, other non-Java projects that do not need to be compiled, you can not need to match the "build" option

Post-Build Action, select the Mail component, and then add the people you want to send and CC

2. Once the configuration is complete, select "Save" directly and select "Build Now"

A) Select the automatically created build task to view the task execution status

b) Enter "Console Output" to view real-time build information

At this point, the entire Jenkins operation is complete!

1.4 Precautions

1, only a set of environment, we all unified use this set can, do not repeat the maintenance of other environments, directly in the link to create a job, convenient unified management.

2, after the boot all files are stored in the/home/user name/.jenkins directory, you can save the configuration by backing up the/.jenkins/job/project name/config.xml file.

3, please do not arbitrarily modify other people's job, create their own just fine.

Chapter II SonarQube Configuration

Sonar is an open source platform for code Quality management that manages the quality of the source code, can detect code quality from seven dimensions, and can support including Java, C #, C + +, PL/sql, Cobol, Javascrip, Groovy, via plug-in form, Python and so on more than 20 programming languages of code quality management and testing.

2.1 installing Sonarqube Preset conditions

1. Installed Java Environment

2, has installed a database (support a variety of databases, we use the company's unified PostgreSQL)

3. Software: http://www.sonarqube.org/downloads/

4. Download Sonarqube and Sonarqube Runner

5. Database configuration:

Enter Database command
Su Postgres
Psql
Create user sonar with password ' sonar ';
Create database sonar owner sonar;
Grant all privileges on the database sonar to sonar;

2.2 installing Sonarqube and Sonar-runner

Installing Sonar and Sonar-runner

A) Extract the downloaded Sonar-3.7.zip package to a Linux path such as/usr/local

b) Unzip the downloaded Sonar-runner-dist-2.3.zip packet to a path/usr/local

c) Add the Sonar_home, sonar_runner_home environment variable and join Sonar_runner_home to Path

D) Modify the sonar configuration file

Modify the/conf/sonar.properties file, configure database settings, and provide support for various types of databases by default
PostgreSQL is used here, so uncomment the PostgreSQL module and

e) Modify the Sonar-runner configuration file

Modify the/conf/sonar-scanner.properties file

2.3 Configure Sonarqube

1, the implementation of the installation target/bin/linux-x86-64/sonar.shstart|stop|restart can start and stop the restart operation.

2, after starting the service to access the http:\\localhost:9000 can

3. After logging in to the Sonarqube server, you can view the issues, metrics, and settings for code rules, quality configuration, quality valves and systems.

4, wherein the quality of the configuration and quality of the valve can be each project to create their own standards, and then specify in the project can be

5, if some indicators of the project needs to be adjusted, you can directly in the issue of the relevant indicators to modify

6, after revising the indicator and the threshold and re-run Sonar-runner will be based on the latest rules analysis

2.4 Configure Sonar-runner

1, in the project source code root directory to create sonar-project.properties configuration file, the file content is as follows

Sonar.projectkey= Project Name

Sonar.projectname=simple Android Project Analyzed with the SonarQube Runner

sonar.projectversion=1.0

Sonar.sources=src

Sonar.binaries=bin/classes

Sonar.language=java

Sonar.sourceencoding=utf-8

Here language can be c/c++/python and other languages

2, because the environment variable is configured, you can execute the sonar-runner command in any directory, log in to Sonaqube after the run is completed, you can view the project analysis just added

2.5 Eclipse Configuring the Sonarlint plug-in (Java)

1. Open Eclipse, enter Help->eclipse Marketplace, enter sonar, install Sonarlint

2. After completing the installation restart Eclipse, select sonar three views in Window->show view

3. Configuring Sonarqube Service information in Sonarqubeservice

4, finally right-click Project Engineering, choose Sonarlint->build ... Then select the corresponding project (you can configure the project on the Sonar service, which can be selected here or not)

5, finally open the class file can see real-time analysis results

This action is only for Eclipse, and other projects can use Sonar-runner analysis to log on to the Sonarqube server to view the results of the analysis.

2.6 Precautions

1, only a set of environment, we all unified use this set can, do not repeat the maintenance of other environments, directly in the link to create a job, convenient unified management.

2, each project can go to the Sonarqube server to customize their own coding specifications, all create their own projects, other projects do not move.

3, Jenkins automated process, call SVN code download will call automatic code analysis, you need to be aware of the code root directory to add sonar-project.properties configuration file.

About quality Improvement during Java development-2 automation

Related Article

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.