Build Jenkins+sonarqube's MAVEN project automation test platform on Fedora 21

Source: Internet
Author: User

Automated testing is a big boost under the Agile development model, and with it, test and development teams can control software quality and iteration cycles in a timely manner, better serve software products, promote software quality and improve development efficiency.

The benefits are so many that I don't have to explain it all.

Recently, the company will develop new products (campus system), in order to avoid the Agile development disorder, poor communication, poor quality and other shortcomings, decided on the automated test platform, the liberation of the Test team, let it focus on more business understanding work, but also from another aspect of the development of the specification of all programmers.

Well, don't say much nonsense, on hard goods.

Preparation phase

First you need to download Sonarqube and Jenkins. In addition, the MySQL database and JDK must be installed first. The JDK version is at least 1.7.

    • Sonarqube official: http://www.sonarqube.org/downloads/
    • Jenkins official: http://pkg.jenkins-ci.org/redhat/

I. Installation Sonarqube:

  1. Upload the downloaded sonar compression package to the server, the directory itself. I'm using the ~/download directory.
  2. Extract, command is:
     unzip  sonarqube-5.1 . Span style= "COLOR: #800080" >1 . zip  
    After the
    has been unzipped, create the sonar directory under the/usr folder, copy the extracted folders into it, and then change the permissions.
     sudo  mkdir /usr/sonar  sudo  CP  sonarqube-< Span style= "COLOR: #800080" >5.1 . 1 /usr/sonar/sudo  chown -R admin/usr/sonar/
  3. When you are finished, you need to make changes to the Sonarqube configuration file. Location:/usr/sonar/sonarqube-5.1.1/conf/sonar.properties
    Use the command:
    VI /usr/sonar/sonarqube-5.1. 1/conf/sonar.properties

    Find these lines and remove the notes. Here we use MySQL, of course, you can also use other databases, remove the corresponding comments on it.

    Sonar.jdbc.username=sonar
    Sonar.jdbc.password=sonar
    sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useunicode=true&characterencoding=utf8& Rewritebatchedstatements=true&useconfigs=maxperformance

    #使用0.0.0.0 is guaranteed to be available at any address
    sonar.web.host=0.0.0.0

    #更改默认的9000端口为9005 to avoid port conflicts with Nodejs.
    sonar.web.port=9005

    After the change is complete, save the exit.

  4. Create sonar libraries and sonar users in the server's MySQL database, and authorize them.
    Mysql-u Root-pcreate DATABASE sonar CHARACTER SET UTF8 COLLATE utf8_general_ci; CREATE USER'Sonar'Identified by'Sonar'; GRANT all on Sonar.* To'Sonar'@'%'Identified by'Sonar';
    GRANT all on Sonar.* To'Sonar'@'localhost'Identified by'Sonar'; FLUSH privileges;

    If you have not installed MySQL database, please Baidu how to install MySQL database on Redhat/fedora/centos and set to boot.
  5. Test if sonar is installed successfully.
    /usr/sonar/sonarqube-5.1. 1/bin/linux-x86-/sonar. SH start
    See Tip:

    Starting SonarQube ...
    Started SonarQube.

    The installation is successful. At this point, you can enter the http://< server ip>:9005 in the terminal to see the graphical interface of the Web page.

  6. Finally, we need to let sonarqube boot. Enter the following commands and content.
    sudo LN -s/usr/sonar/sonarqube-5.1. 1/bin/linux-x86-/sonar. sh /usr/bin/sonarsudovi /usr/lib/systemd/system/sonar.service
    Write in new file:
    # # Simple Sonar systemd servicefile# # SYSTEMD supports lots of fancy features, look here (and linked docs) fora full list:# http://www.freedesktop.org/software/systemd/man/systemd.exec.html# # Note:thisfile(/usr/lib/systemd/system/Sonar.service) # 'll be overwritten in package upgrade, please copy thefileto##/etc/systemd/system/sonar.service## to Makeneeded changes.## systemd-Delta can used to check differences between the Sonar.service files.#[unit]description=sonarqube System5.1.1 After=network.target Remote-fs.target nss-Lookup.targetafter=Syslog.target[install]wantedby=multi-User.targetalias=Sonar.service[service]type=forking# Execute pre and post scripts as Rootpermissionsstartonly=true# Start Main Serviceexecstart=/usr/bin/sonar start# Reload main serviceexecreload=/usr/bin/sonar restart# Stop main serviceexecstop=/usr/bin/sonar stop# Give upif PingDon't get an answerTimeoutsec= -privatetmp=true
    Then save the exit.

    At this point, you can use the powerful systemctl command to perform sonarqube start/reload/stop operations.
    Start command: sudo systemctl start sonar.service
    Restart command: sudo systemctl restart Sonar.service
    Stop Minglin: sudo systemctl stop Sonar.service

    Boot start command: sudo systemctl enable Sonar.service
    Remove boot start: sudo systemctl disable Sonar.service
    View boot status: sudo systemctl status Sonar.service

Two. Install Jenkins:

  1. I chose Yum to install Jenkins. First add the library and key.
     sudo  wget -o/etc/yum . Repos.d/jenkins.repo http://  pkg.jenkins-ci.org/redhat/jenkins.repo   sudo  rpm--import http://  Pkg.jenkins-ci.org/redhat/jenkins-ci.org.key  

    and then enter the command to install Yum.
     sudo yum  install  Jenkins 
    The
    installation package size is approximately 60M.
  2. After the installation is complete, you need to modify the next Jenkins port to avoid collisions with Tomcat.
    sudo VI /etc/sysconfig/jenkins

    Find two places:

    jenkins_port= "8080"

    Jenkins_ajp_port= "8009"
    Change it to (the port number can be changed at will, as long as it does not conflict with other programs is good):

    Jenkins_port= "8189"

    Jenkins_ajp_port= "8190"

  3. Using the command: sudo systemctl start jenkins.service start the Jenkins service, enter in the client's browser address bar: http://< Server ip>:8189 to see the Jenkins page.:
  4. If the startup error occurs and the/usr/bin/java is not found, your JDK configuration is incorrect. You can use Java–version to see if the installation is successful and if the version is correct. If it is not a problem, still report this error, you can copy the JDK version number: for example 1.8.0 _45. Then, find/etc/init.d/jenkins This file, edit it.
    sudo VI /etc/init.d/jenkins

    Find this code:
     candidates= "/etc/alternatives/java /usr/lib/jvm/java-1.6 . 0 /bin/java /usr/lib/jvm/jre-1.6 . 0 /bin/java /usr/lib/jvm/java-1.7 . 0 /bin/java /usr/lib/jvm/jre-1.7 . 0 /bin/java /usr/lib/jvm/java-1.8 . 0 /bin/java /usr/lib/jvm/jre-1.8 . 0 /bin/java /usr/bin/java 

    Discover that there is no directory of our JDK files, add
    /usr/java/jdk1. 8. 0_45/bin/java

    After this code, the effect is as follows:
    candidates="/etc/alternatives/Java/usr/lib/jvm/java-1.6.0/bin/Java/usr/lib/jvm/jre-1.6.0/bin/Java/usr/lib/jvm/java-1.7.0/bin/Java/usr/lib/jvm/jre-1.7.0/bin/Java/usr/lib/jvm/java-1.8.0/bin/Java/usr/lib/jvm/jre-1.8.0/bin/Java/usr/bin/Java/usr/java/jdk1.8.0_45/bin/Java"

    Save exit, then start, success!
    At this point, Jenkins is installed.
  5. 接下来,我们需要配置Jenkins中的sonar插件.
    在浏览器中输入http://<服务器IP>:8189来访问Jenkins的主页,点击左侧的”系统管理”.:


    再选择”管理插件”


    选择”可选插件”,在右上角的搜索栏中输入sonar,然后在”SonarQube Plugin”前面打钩,点击”直接安装”按钮,等待重启.页面刷新后,就安装好了插件了.

    配置SonarQube插件,同样是在”系统管理”中的”系统设置”中,找到位置:



    如果从未添加过SonarQube,则点击”Add SonarQube”,然后点击”高级”.:

Fill in the corresponding content, it is configured. In the next chapter, I will send out how to test and report how to analyze.

Build Jenkins+sonarqube's MAVEN project automation test platform on Fedora 21

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.