zoukankan      html  css  js  c++  java
  • Jenkins整合SonaQube

    具体的流程如下:

     安装SonarQube Scanner插件

     添加SonarQube凭证

     

    Jenkins进行SonarQube配置
    Manage Jenkins->Configure System->SonarQube servers

    Manage Jenkins->Global Tool Configuration 

     SonaQube 关闭审查结果上传到SCM功能

    在项目添加SonaQube代码审查(非流水线项目)
    添加构建步骤:

     正常的项目,没有问题

     错误的代码

    package com.topcheer;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    
    /**
     *
     */
    public class HelloServlet extends HttpServlet {
    
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            super.doPost(req,resp);
        }
    
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            //模拟代码错误
            int i = 100/0;
    
            //模拟冗余代码
            int a = 100;
            a = 200;
    
    
            resp.getWriter().write("hello Servlet!");
        }
    }

     

    在项目添加SonaQube代码审查(流水线项目)
    1)项目根目录下,创建sonar-project.properties文件

    # must be unique in a given SonarQube instance
    sonar.projectKey=web_demo_pipeline
    # this is the name and version displayed in the SonarQube UI. Was mandatory
    sonar.projectName=web_demo_pipeline
    sonar.projectVersion=1.0
    # Path is relative to the sonar-project.properties file. Replace "" by "/" on
    # This property is optional if sonar.modules is set.
    sonar.sources=.
    sonar.exclusions=**/test/**,**/target/**
    sonar.java.source=1.8
    sonar.java.target=1.8
    # Encoding of the source code. Default is default system encoding
    sonar.sourceEncoding=UTF-8

     结果:

  • 相关阅读:
    leetcode刷题笔记 217题 存在重复元素
    leetcode刷题笔记 二百零六题 反转链表
    leetcode刷题笔记 二百零五题 同构字符串
    20201119日报
    np.percentile 和df.quantile 分位数
    建模技巧
    np.where() 条件索引和SQL的if用法一样,或者是给出满足条件的坐标集合
    np.triu_indices_from() 返回方阵的上三角矩阵的索引
    ax.set_title() 和 plt.title(),以及df,plot(title='')
    信用卡模型(三)
  • 原文地址:https://www.cnblogs.com/dalianpai/p/12249303.html
Copyright © 2011-2022 走看看