SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

1.SonarQube kernel parameters before deployment configuration and Java environment configuration

1) modify the kernel parameters that meet environmental requirements

[sonarqube the root @ ~] # Vim /etc/sysctl.conf 
vm.max_map_count = 262144 
fs.file-max = 65536 
kernel parameter [root @ sonarqube ~] # sysctl -p # commencement modified 
...... 
vm.max_map_count = 262144 
FS .file-max = 65536

2) modify the native security policy parameters limit

[root @ sonarqube ~] # vim /etc/security/limits.conf 
...... 
sonarqube - nofile 65536 
sonarqube - nproc 2048

3) Configure the java environment (at least jdk-8 openjdk-8 or version)

[root@sonarqube ~]# ls /usr/local/src/
 jdk-8u211-linux-x64.tar.gz
[root@sonarqube src]# tar xvf jdk-8u211-linux-x64.tar.gz
[root@sonarqube src]#ln  -sv jdk1.8.0_211  jdk
[root@sonarqube src]#ln  -sv   jdk
[root@sonarqube src]# ln -sv jdk/bin/*  /usr/bin
[root@sonarqube src]# vim /etc/profile
……
export export LANG="en_US.utf-8"
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar

2. Database preparation (sonarqube7.9 version is no longer supported mysql, here to sonarqube6.7 for example, and requires at least mysql5.6)

1) the definition of the relevant path ahead of good data and database users start

[root @ sonarqube ~] # saved data path mkdir / data / mysql # database 
[root @ sonarqube ~] # mkdir / data / binlog / bin # binary log store directory 
[root @ sonarqube ~] # chown mysql.mysql - R & lt / Data / the binlog 
[sonarqube the root @ ~] # chown -R & lt mysql.mysql / Data / MySQL 
[sonarqube the root @ ~] # the useradd -s / sbin / nologin / MySQL -u 1234

2) Download the source code archive msyql

[root@sonarqube ~]# ls /apps/mysql/
mariadb-10.2.23-linux-x86_64.tar.gz

3) unzip and create a soft link

[root@sonarqube ~]# tar xvf mariadb-10.2.23-linux-x86_64.tar.gz 
[root@sonarqube ~]# ln -sv mariadb-10.2.23-linux-x86_64 mysql

4) Create a soft link executable binary files

[root@sonarqube ~]# ln -sv /apps/mysql/mysql/bin/* /usr/sbin/

5) Modify the startup script file mysql

[sonarqube the root @ ~] # Vim /apps/mysql/mysql/support-files/mysql.server 
...... 
the basedir = / Apps / mysql / mysql # mysql installation operation defined directory 
datadir = / data / mysql # database file defined mysql save directory 
......

6) host name resolution proposed changes would modify the local hostname resolves to the local loopback

[root@sonarqube ~]# vim /etc/hosts
127.0.0.1 sonarqube localhost localhost.localdomain localhost4 localhost4.localdomain4
……

Initialization 7) execution of the database

[root@sonarqube scripts]# pwd
/apps/mysql/mysql/scripts
[root@sonarqube scripts]# ls
mysql_install_db
[root@sonarqube scripts]# mysql_install_db --user=mysql --datadir=/data/mysql

8) Start mysql service

[root@sonarqube support-files]# pwd
/apps/mysql/mysql/support-files
[root@sonarqube support-files]# bash mysql.server start

9) Check whether the port to start 3306

[root@sonarqube ~]# ss -tnlp
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port
……
LISTEN     0            80                          :::3306                                              :::*                  
 users:(("mysqld",pid=9865,fd=18))
……

10) Create a database and authorize sonarqube (character set utf8)

MariaDB [(none)]> create database sonarqube default character set utf8 collate utf8_general_ci;
MariaDB [(none)]> grant all on sonarqube.* to sonarqube@'192.168.1.31' identified by '123456';

11) tests whether the user can log database sonarqube

[root@sonarqube ~]# mysql -usonarqube -p123456 -h192.168.1.31
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.2.23-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, , MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| sonarqube          |
| test               |
+--------------------+
3 rows in set (0.00 sec)

Installation Configuration of 3.sonarqube-6.7

1) Download the source archive

[root@sonarqube ~]# ls /apps/sonarqube
sonarqube-6.7.7.zip

2) extract the sonarqube source package, and creates a soft link

[root@sonarqube sonarqube]# unzip sonarqube-6.7.7.zip
[root@sonarqube sonarqube]# ln -sv sonarqube-6.7.7 sonarqube
‘sonarqube’ -> ‘sonarqube-6.7.7’

3) Create a user and change the directory's owner is a group

[root@sonarqube sonarqube]# useradd  sonarqube
[root@sonarqube sonarqube]# chown sonarqube.sonarqube -R /apps/sonarqube/

4) Configuration sonarqube profile

[root@sonarqube conf]# su - sonarqube
Last login: Mon Jul 29 13:48:33 CST 2019 on pts/1
[sonarqube@sonarqube ~]$ cd /apps/sonarqube/sonarqube
[sonarqube@sonarqube sonarqube]$ grep '^[a-Z]' conf/sonar.properties
sonar.jdbc.username=sonarqube
sonar.jdbc.password=123456
sonar.jdbc.url=jdbc:mysql://192.168.1.31:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.web.host=0.0.0.0
sonar.web.port=9000

5) Start sonarqube Service

[sonarqube@sonarqube sonarqube]$ ./bin/linux-x86-64/sonar.sh  start
Starting SonarQube...
Started SonarQube.

6) Check listening port

[sonarqube@sonarqube sonarqube]$ ss -tnlp
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128               *:111                           *:*                  
LISTEN     0      128               *:22                            *:*                  
LISTEN     0      100       127.0.0.1:25                            *:*                  
LISTEN     0      1         127.0.0.1:32000                         *:*                   
users:(("java",pid=10447,fd=4))
LISTEN     0      25               :::9000                         :::*                   
users:(("java",pid=10544,fd=116))
LISTEN     0      128    ::ffff:127.0.0.1:9001                         :::*                  
 users:(("java",pid=10467,fd=100))
LISTEN     0      80               :::3306                         :::*                  
LISTEN     0      128              :::111                          :::*                  
LISTEN     0      128              :::22                           :::*                  
LISTEN     0      100             ::1:25                           :::*                  
LISTEN     0      50     ::ffff:127.0.0.1:9092                         :::*                  
 users:(("java",pid=10544,fd=148))

7) browser access sonarqube

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

8) logged on user name and password are admin by default

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

9) the success of the web page login sonarqube

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

4. A plug installation Chinese, Chinese interface displayed

1) Click on administration → Marketplace, Chinese direct search plugin

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

2) Click the install install

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

3) Restart Service

[sonarqube@sonarqube linux-x86-64]$ ./sonar.sh restart

4) When accessed again, the display Chinese interface

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

5) Chinese View installed plug-in package

[sonarqube@sonarqube sonarqube]$ ll extensions/plugins/
……
-rw-r--r-- 1 sonarqube sonarqube   38307 Jul 29 15:05 sonar-l10n-zh-plugin-1.19.jar
……

6) installation, java, php and other development language plug-ins in order to scan the relevant language code

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment
SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment
SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

The deployment scanner sonar-scanner (sonarqube scan code by the scanner)

1) scanner binary address ×××

https://binaries.sonarsource.com/Distribution/sonar-scanner-cli

2) Download the scanner to the specified directory

[root@sonarqube sonarscanner]# pwd
/apps/sonarscanner
[root@sonarqube sonarscanner]# ll -h
total 41M
-rw-r--r-- 1 root root 41M Jul 22 19:31 sonar-scanner-cli-4.0.0.1744-linux.zip

3) extract the source code and binary scanner to create a soft link

[root@sonarqube sonarscanner]# unzip sonar-scanner-cli-4.0.0.1744-linux.zip
[root@sonarqube sonarscanner]# ls
sonar-scanner-4.0.0.1744-linux  sonar-scanner-cli-4.0.0.1744-linux.zip
[root@sonarqube sonarscanner]# ln -sv sonar-scanner-4.0.0.1744-linux sonar-scanner
‘sonar-scanner’ -> ‘sonar-scanner-4.0.0.1744-linux’

4) modify the configuration file

[root@sonarqube sonar-scanner]# vim conf/sonar-scanner.properties
……
#----- Default SonarQube server
sonar.host.url=http://192.168.1.31:9000

#----- Default source code encoding
sonar.sourceEncoding=UTF-8

5) Prepare a test code to the compressed packet and extract the current directory

[root@sonarqube code-test]# pwd
/apps/code-test
[root@sonarqube code-test]# ll -h
total 6.5M
-rw-r--r-- 1 root root 6.5M Nov 21  2018 sonar-examples-master.zip
[root@sonarqube code-test]# unzip sonar-examples-master.zip

Under 6) to a source of the test path

[root@sonarqube php-sonar-runner]# pwd
/apps/code-test/sonar-examples-master/projects/languages/php/php-sonar-runner
[root@sonarqube php-sonar-runner]# ll
total 12
-rw-r--r-- 1 root root 453 Jul 25  2016 README.md
-rw-r--r-- 1 root root 331 Jul 25  2016 sonar-project.properties
drwxr-xr-x 2 root root  22 Jul 25  2016 src
-rw-r--r-- 1 root root 272 Jul 25  2016 validation.txt

7) The default configuration file generated code

[root @ sonarqube PHP-SONAR-Runner] CAT sonar-project.properties # 
# the Required the Metadata 
sonar.projectKey = org.sonarqube: the Simple PHP-Scanner-# sq-volume custom project Key 
sonar.projectName the Simple Project :: PHP = :: sonarQube Scanner # project name 
sonar.projectVersion = # version 1.0 project 

# Comma-Separated paths to Directories with Sources (required) 
sonar.sources source path = src # 

# Language 
type sonar.language = php # source code for PHP code 

# encoding of Source Files the 
sonar.sourceEncoding = UTF-encoded format. 8 #

8) performing scanning in the current code path

[root@sonarqube php-sonar-runner]# /apps/sonarscanner/sonar-scanner/bin/sonar-scanner
……
tly specify it.
INFO: Calculating CPD for 1 file
INFO: CPD calculation finished
INFO: Analysis report generated in 213ms, dir size=34 KB
INFO: Analysis reports compressed in 42ms, zip size=10 KB
INFO: Analysis report uploaded in 3108ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://192.168.1.31:9000/dashboard/index/org.sonarqube:php-simple-sq-scanner
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://192.168.1.31:9000/api/ce/task?id=AWw9AEUVHii-ILef0qYq
INFO: Task total time: 17.226 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 29.467s
INFO: Final Memory: 7M/115M
INFO: ------------------------------------------------------------------------

Generated after 9) web end view scan recording

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

6.jenkins configuration sonarqube-scanner and automatically testing jenkins code, automatically deploy

1) install the scanner plug-in

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

2) Click the system setting sonarqube Service

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

3) Add sonarqube services and customize the service name, and the url address

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

4) automatically install the scanner scanner

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

5) If you have installed scanner scanners do not need to be installed automatically, added directly to the working directory scanner

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

6) Create a new project code-test-job in jenkins

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

7) configure this program configure

Gitlab designated warehouse source, authentication

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

Password build trigger keys

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

Scan configuration parameter code, which specifies the type of detection code encoding formats, paths, etc.

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

8) Hook in gitlab server to add jenkins address authentication, in order to realize the project of building an automatic trigger jenkins

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

9) clone gitlab warehouse code and modify the code, and then upload it to trigger gitlab warehouse project to build jenkins

Designated clone develop branch code
root@1804:/data/src# git clone -b develop http://192.168.1.30/jie/web-page.git
Cloning into 'web-page'...
Username for 'http://192.168.1.30': jie
Password for 'http://[email protected]': 
remote: Enumerating objects: 30, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 30 (delta 4), reused 27 (delta 4)
Unpacking objects: 100% (30/30), done.
Add a source file to the directory php clone
root@ubuntu1804:/data/src/web-page# mv /data/Math.php ./
root@ubuntu1804:/data/src/web-page# ls
index.html  Math.php
Add the code to the local staging area
root@ubuntu1804:/data/src/web-page# git add ./*
Code submitted to the work area and specify the version number in order to submit multiple submissions of distinction
root@ubuntu1804:/data/src/web-page# git commit -m 'v11'
[develop 9e106d4] v11
 1 file changed, 214 insertions(+)
 create mode 100644 Math.php
Code library code is uploaded to gitlab
root@ubuntu1804:/data/src/web-page# git push
Username for 'http://192.168.1.30': jie
Password for 'http://[email protected]': 
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 1.75 KiB | 893.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: 
remote: To create a merge request for develop, visit:
remote:   http://192.168.1.30/jie/web-page/merge_requests/new?merge_request%5Bsource_branch%5D=develop
remote: 
To http://192.168.1.30/jie/web-page.git
     3fb434f..9e106d4  develop -> develop

10) Check the gitlab server-side code has been successfully submitted

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

Triggered automatically after 11) to submit code to the project build gitlab jenkins

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

12) View project to build a successful console output information

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

13) See sonarqube-server server php code recorded test results

SonarQube code detection and deployment service implementation code jenkins automated testing, automated deployment

Guess you like

Origin www.linuxidc.com/Linux/2019-07/159715.htm