DevOps Learning Practice (v) Jenkins works with Ant and FindBugs

Source: Internet
Author: User
Tags centos centos server

Prior to the introduction of Jenkins inside the findbugs mainly using MAVEN, but in many cases, the project uses ant for compiling and packaging, through the Jenkins Ant findbugs combination of the way can be continuous integration. Jenkins is characterized by the ease of integration of these tools, in order to reduce the coupling with the engineering itself, so the idea is that the ant compilation project and Ant call FindBugs through Jenkins in 2 steps, so that the convenience of more flexibility.

Here is an introduction to Ant's Installation and configuration , goals and environment

Prepare to install Ant on centos6.5 with Jenkins and install the environment as follows: 192.168.136.144 CentOS 6.5

Call Ant and FindBugs through Jenkins for project jar packages or class check II, ant installation and configuration 1, download ant

To the ant website to download the required ant package, the URL is: http://ant.apache.org/bindownload.cgi

Because it is installed on CentOS, the selected package is: 2, Deployment and configuration

Upload the downloaded package to the target server and unzip it using tar:

    Tar  -vxf  
Extracted directory:/home/nmc/dev/apache-ant-1.10.1 Some students like to put in the/opt directory, some like to put to/usr directory, where to see a person likes. I was put to/usr/ant, so execute:
    MV  /home/nmc/dev/apache-ant-1.10.1  /usr/ant
The next step is to configure:

    
In this configuration file, configure the following:

Export  ant_home=/usr/ant 
After saving, exit the file editor and then execute:

Source/etc/profile
The purpose of the execution of this order is not to start, immediately effective


Finally, to verify that the ant command is successful, we can execute ant, and if the hint does not build.xml that the ant itself is already installed, you can also use ant-version to see if the version information will be returned correctly.

[Root@cwqsolo apache-ant-1.10.1]# ant
Buildfile:build.xml does not exist!
Build failed
[Root@cwqsolo apache-ant-1.10.1]# ant-version
Apache Ant (TM) version 1.10.1 compiled on February 2 2017
third, the installation and configuration of FindBugs

Since FindBugs 3.0 requires Java 1.7 Mates, considering that we actually work, there are many projects, there are Java 1.6, 1.7, 1.8 coexistence situation, so the use of FindBugs 2.0.2 (subsequent proof that this is a wrong choice, because 2.0.2 to 1.8 Does not support, weigh the pros and cons, so the final project all need to be in Java 1.7 and later. ) 1, download fingbugs

Select findbugs-2.0.2.tar.gz Download via the url:https://sourceforge.net/projects/findbugs/files/findbugs/2.0.2/below. Download upload to CentOS server 144 and Unzip 2, deploy

Put the extracted directory into the directory you want by MV, in this case:/home/nmc/dev/devops/findbugs

In fact, the FindBugs directory, only need to leave the Lib directory, other directories and files can be deleted (especially in the case of Ant call), in addition, there is an ant call to build file, in this case findbugsbuild.xml

<?xml version= "1.0"?> <project name= "Check" default= "Default" basedir= "." > <property name= "src.dir" value= "${basedir}/src"/> <property name= "Class.dir" value= "${basedir}/WebRoot /web-inf/classes "/> <property name=" Dist.dir "value=" ${basedir}/dist "/> <property name=" Findbugs.dir "va Lue= "/home/nmc/dev/devops/findbugs"/> <path id= "Findbugs.path" > <fileset dir= "${findbugs.dir}"
            ; <include name= "**/*.jar"/> </fileset> </path> <!--================================ ===================================-<!--Findbugs Build-<!--================================= ==================================--<taskdef name= "FindBugs" Classname= "  
      Edu.umd.cs.findbugs.anttask.FindBugsTask "classpathref=" Findbugs.path "/> <target name=" FindBugs "> <mkdir dir= "${basedir}/findbugs"/> <findbugs home= "${findbugs.dir}" Output= "xml" outputfile= "${basedir}/findbugs/findbugs_errors.xml" > <sourcepath path= "${src.dir}"/> <class location= "${class.di\r}"/> </findbugs> </target> <target nam
 E= "Default" depends= "FindBugs" > </target> </project>
The FindBugs directory is as follows:
[Root@cwqsolo findbugs]# ls
findbugsbuid.xml  Lib

3, manual verification findbugs normal work

Entry into the test and inspection of the project, copy Findbugsbuid.xml

To the engineering catalog, execute Ant-file findbugsbuid.xml

[Root@cwqsolo cwq_testproject1]# ant-f findbugsbuid.xml buildfile:/home/nmc/dev/devops/jenkins/workspace/cwq_ Testproject1/findbugsbuid.xml findbugs: [findbugs] executing findbugs findbugstask from ant task [findbugs] Running Fin
 Dbugs ... [FindBugs] The following classes needed for analysis were missing: [FindBugs] kafka.consumer.ConsumerConfig [findbugs] Kafka.ja Vaapi.consumer.ConsumerConnector [FindBugs] kafka.consumer.KafkaStream [findbugs] kafka.consumer.ConsumerIterator [ FindBugs] kafka.message.MessageAndMetadata [findbugs] kafka.consumer.Consumer [findbugs] Kafka.producer.ProducerCo Nfig [FindBugs] kafka.producer.KeyedMessage [findbugs] kafka.javaapi.producer.Producer [findbugs] Kafka.serialize
 R.stringencoder [findbugs] Warnings generated:1 [findbugs] Missing classes:9 [findbugs] Calculating exit code ... [FindBugs] Setting ' Missing class ' flag (2) [findbugs] Setting ' bugs found ' flag (1) [FindBugs] Exit code set to:3 [FindBugs] Jav A ReSult:3 [findbugs] Classes needed for analysis were missing [findbugs] Output saved To/home/nmc/dev/devops/jenkins/work Space/cwq_testproject1/findbugs/findbugs_errors.xml default:build Successful total time:4 seconds [Root@cwqsolo cwq_t  estproject1]#

Once executed, the build successful appears to be successful. iv. configuration in Jenkins

Jenkins Component Engineering This piece is not detailed, just describe the basic configuration of engineering components, how to join FindBugs 1, add build

Add a copy action to the original build ant build action to copy the Code walk-through configuration file to the project after Ant compiles the project.

In this component action, a new ant build action is added, in a way, Jenkins is a tool that provides an interface for various actions in series.

Then, in the post-build action, publish the results of findbugs (prior to installing the FindBugs plugin in Jenkins, see the previous data)

Once these are configured, you can save them and build them.

Note FindBugs Trend chart, need to build 2 times before it will come out, if everything goes well, you see the build trend map and FindBugs link, click the link can see the specific bugs five: add:

1, findbugs 2.0.2 error

[FindBugs] Unable to get xclass for Java/lang/class
[FindBugs] Java.lang.ArrayIndexOutOfBoundsException
[FindBugs] Jul 8:17:35 PM Edu.umd.cs.findbugs.TextUIBugReporter reportanalysiserror
[FindBugs] Severe:couldn ' t get class info for Java/util/concurrent/concurrentmap
[FindBugs] java.lang.arrayindexoutofboundsexception:28526

----FIX: This is because the project was compiled with Java 1.8, select FindBugs 3.0 or later


2. If your project requires JDK 1.7 then please reduce ant to 1.9 I use 1.9.3 no problem, otherwise there will be JDK version error, error code: 52


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.