First, install and configure Jenkins.
Jenkins, formerly known as Hudson, is an extensible, continuous integration engine. Mainly used for:
Build/test software projects, such as CruiseControl and Damagecontrol, in a continuous and automated manner.
Monitor some tasks that are scheduled to execute.
It has two installation methods, one is standalone, the other is to run as a Tomcat War plugin (JDK environment is essential), first download Tomcat, extract tomcat to a directory, such as/usr/local, into the/bin directory under Tomcat, Start Tomcat, Put the Jenkins.war file in the WebApps directory under Tomcat, when you start Jenkins, the Jenkins directory is automatically created in the WebApps directory, so you need to add the Jenkins directory behind the IP address bar, such as http:// ip/jenkins:8080.
Using command-line commands scanner and runner to parse the code, you need to manually download the source code folder to the server where the analysis command is running, and the persistence analysis experience is poor. Using Jenkins can automatically download the source code, and automatically complete the analysis, but also set up scheduled tasks, to achieve full-automatic, is a necessary tool for lazy people ah!
In the following example, the source code is automatically analyzed using Git+scanner and Git+maven respectively. Basically, the first thing to do is to have a code base, such as BitBucket, and then configure Git to automatically download the latest code from the codebase in Jenkins, and finally call scanner or MAVEN to send the code to Sonarqube for analysis. The analysis report of this project is shown on Sonarqube.
1. Install Jenkins and Maven independently in CentOS.
Wget-o/etc/yum.repos.d/jenkins.repo Https://pkg.jenkins.io/redhat/jenkins.repo #添加Jenkins的源
RPM--import Https://pkg.jenkins.io/redhat/jenkins.io.key #安装Jenkins的Key
Yum Install Jenkins #安装Jenkins
ll/usr/lib/jenkins/#安装成功后可以查看到Jenkins的war包, if you want to upgrade Jenkins, just download this war package to replace it.
Vim/etc/sysconfig/jenkins #配置Jenkins, the default boot port 8080, if you do not need to change the configuration file can not move
Systemctl Start Jenkins #启动Jenkins服务
Chkconfig Jenkins on #设置为开机自动启动
Cat/var/lib/jenkins/secrets/initialadminpassword #显示Jenkins安装后的Admin的授权号码, copy it and paste it on the Web page to complete the authorization.
2, on other computer browser access to Jenkins, Access address:/HTTP Server ip:8080, paste on the copy of the authorization number, after the successful authorization, set the Administrator account and password, then install the default components, and finally into the boot interface:
650) this.width=650; "title=" Image_thumb1 "style=" border-right-width:0px;background-image:none; border-bottom-width:0px;padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px; "border=" 0 "alt = "IMAGE_THUMB1" src= "Http://s3.51cto.com/wyfs02/M01/89/43/wKiom1gN2c_BQ5AVAADHqMwOCOY785.png" width= "1098" height = "703"/>
Download and install the Sonarqube plugin plugin in Jenkins.
650) this.width=650; "title=" IMAGE_THUMB2 "style=" border-right-width:0px;background-image:none; border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px; " Border= "0" alt= "IMAGE_THUMB2" src= "http://s3.51cto.com/wyfs02/M00/89/41/wKioL1gN2dHh96NqAAGII2YUTtc859.png" width = "1092" height= "710"/>
650) this.width=650; "title=" Image_thumb31 "style=" border-right-width:0px;background-image:none; border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px; " Border= "0" alt= "image_thumb31" src= "Http://s3.51cto.com/wyfs02/M01/89/43/wKiom1gN2dLBT4urAAFYsGIQFCY127.png" Width= "1092" height= "710"/>
When the installation is complete, Jenkins automatically restarts.
650) this.width=650; "title=" Image_thumb4 "style=" border-right-width:0px;background-image:none; border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px; " Border= "0" alt= "image_thumb4" src= "http://s3.51cto.com/wyfs02/M00/89/43/wKiom1gN2dODADnxAAAKw19U2VI988.png" width = "346" height= "/>"
3. Configuring Sonar in Jenkins and setting the global configuration
Find Sonaqube configuration items in System configuration of Jenkins home page
650) this.width=650; "title=" Image_thumb5 "style=" border-right-width:0px;background-image:none; border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px; " Border= "0" alt= "image_thumb5" src= "http://s3.51cto.com/wyfs02/M02/89/43/wKiom1gN2dORSKcSAAD3pJfaGmA669.png" width = "948" height= "620"/>
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m02/89/41/wkiol1gn2dtzjm9haadodbh7nyk800.png "height=" 846 "/>
Setting the Global tool configuration
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M00/89/41/wKioL1gN2daiF8jeAAFuDVF0d8s984.png "height=" 698 "/>
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M01/89/41/wKioL1gN2dbxWFzYAAD_s7V6t8w656.png "height=" 946 "/>
4. Create a new free project and configure the scanner
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M02/89/43/wKiom1gN2dfjiMnqAAEMkTIV72A309.png "height=" 1003 "/>
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M01/89/41/wKioL1gN2dnCmapbAAGpluQEcLI902.png "height=" 937 "/>
Found in BitBucket to analyze the project source git address, copy down
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M02/89/43/wKiom1gN2drj9VT2AADo85DGuDA473.png "height=" 624 "/>
Configure the source code in Git to get the address, and increase in the bitbucket with the least Read permissions of the user name and password, to achieve the ability to download source code from the source code library.
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M02/89/41/wKioL1gN2dvDKMLdAAEI1fRoZHY604.png "height=" 959 "/>
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M00/89/43/wKiom1gN2dywkiwnAADlG38sa2U423.png "height=" 891 "/>
Building scanner to perform code analysis
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M01/89/43/wKiom1gN2d6wdKKlAAEZIgCW0ec145.png "height=" 950 "/>
Copy the scanner configuration file into the analysis properties, and the project name, primary key, and version number are modified according to actual needs.
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M02/89/43/wKiom1gN2d_z-E3kAAEpgud0fag800.png "height=" 947 "/>
Build your first code analysis now
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M02/89/43/wKiom1gN2eDxaE27AADifiM4chQ286.png "height=" 952 "/>
View the execution process
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m02/89/41/wkiol1gn2egaxbvuaaewji6jnxi832.png "height=" 916 "/>
An error occurred, and the FindBugs plugin in the Sonarqubo conflict, need to delete the plugin in Sonarqubo, and then perform the analysis will be successful
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m00/89/43/wkiom1gn2ekdtldvaad1tpzy1g8649.png "height=" 898 "/>
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M01/89/43/wKiom1gN2eOSHn9-AAEMIMuYC_8575.png "height=" 918 "/>
Analysis success
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m00/89/41/wkiol1gn2ewbpjeaaadnvjxezu0720.png "height=" 946 "/>
View analysis results in Sonarqube
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M02/89/43/wKiom1gN2eXDLX_9AAC7ZHs4418524.png "height=" 564 "/>
5. Install Maven and create a new MAVEN project to configure
Installing MAVEN in System Management-global tools management
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M02/89/41/wKioL1gN2eahoeiqAAE4xFZLNaU568.png "height=" 575 "/>
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M02/89/43/wKiom1gN2eeywRv9AACqVOJh3es579.png "height=" 945 "/>
Pick a name and save it.
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M00/89/41/wKioL1gN2efisdcVAACt_dHYbb4772.png "height=" 941 "/>
MAVEN is not installed now and will be installed only if you are building now, then create a new MAVEN project
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M00/89/43/wKiom1gN2erT_jEVAAGtjoKLQZQ387.png "height=" 957 "/>
The same configuration git
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M01/89/43/wKiom1gN2evg-QePAADK6L723FQ290.png "height=" 675 "/>
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M02/89/43/wKiom1gN2euTi8lhAABvJjKxlgs220.png "height=" 433 "/>
The "Pom.xml" in the source directory is a MAVEN-generated configuration file in eclipse that needs to be configured in Eclipse and generated in the root directory.
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M00/89/43/wKiom1gN2evSDKQ9AABOY0PbePA369.png "height=" 246 "/>
Add an execution shell
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M02/89/43/wKiom1gN2eyxcAdXAABqZ8OVJTU680.png "height=" 403 "/>
Write the following command
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M00/89/41/wKioL1gN2ezhQMnoAABzLjChMJ4556.png "height=" 572 "/>
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M00/89/43/wKiom1gN2e3R0YHpAAED11DajBM336.png "height=" 815 "/>
The first time is very slow, because you have to download the MAVEN installation, then perform code analysis, and then more quickly, the build succeeded in console output with success hints
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M00/89/41/wKioL1gN2e2h5er9AAArkgSgeK8112.png "height=" 280 "/>
View in sonar (this is a configured dashboard)
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m02/89/41/wkiol1gn2e7h86iqaaiypf2byfy982.png "height=" 544 "/>
This article from the "Strong Technical communication blog," Please be sure to keep this source http://newthink.blog.51cto.com/872263/1865134
Sonar6.0 application four: Integration with Jenkins (Scanner+maven)