zoukankan      html  css  js  c++  java
  • Jenkins+SonarQube代码审查

    1. 环境

    Centos 7

    Jenkins

    SonarQube 7.9

    Centos7安装SonarQube

    centos7安装jenkins

    2. SonarQube生成token

    SonarQube默认账户是admin/admin

    创建token

    个人头像-->My Account-->Security

    700ba7c1c925ec53ff96159a9c84bf49040c34c0
    

    3. Jenkins安装SonarQube Scanner插件

    4. Jenkins添加SonarQube凭证

    5. Jenkins进行SonarQube配置

    Manage Jenkins->Configure System->SonarQube servers

    应用,保存

    Jenkins 安装SonarQube-scanner

    Manage Jenkins->Global Tool Configuration

    保存,应用

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

    7. 在项目添加SonaQube代码审查(非流水线项目)

    在现有的非流水线项目中添加构建步骤:

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

    应用,保存

    点击Build Now

    8. 在项目添加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
    prior to SonarQube 6.1.
    sonar.projectName=web_demo_pipeline
    sonar.projectVersion=1.0
    # Path is relative to the sonar-project.properties file. Replace "" by "/" on Windows.
    # This property is optional if sonar.modules is set.
    sonar.sources=.
    sonar.java.binaries=./target/classes
    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
    

    2. 修改Jenkinsfile,加入SonarQube代码审查阶段

    pipeline {
       agent any
    
       stages {
          stage('pull code') {
             steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/${branch}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'cce455e2-ba69-459e-93bc-c58ce1e6278f', url: 'ssh://git@192.168.2.4:23456/itheima_group/web_demo.git']]])
             }
          }
          stage('build code') {
             steps {
                sh label: '', script: 'mvn clean package'
             }
          }
          stage('check code') {
             steps {
                 script  {
                     scannerHome = tool 'sonar-scaner'
                 }
                 withSonarQubeEnv('sonarqube')  {
                     sh "${scannerHome}/bin/sonar-scanner"
                 }
             }
          }
          stage('deploy code') {
             steps {
                deploy adapters: [tomcat9(credentialsId: 'da6aa960-cb2b-415f-a31e-e161ba704f28', path: '', url: 'http://192.168.2.5:8080')], contextPath: null, war: 'target/*.war'
             }
          }
       }
       post {
         always {
           emailext body: '${FILE,path="email.html"}', subject: '构建通知:${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}!', to: '508110504@qq.com'
         }
       }
    }
    

    提交gitlab,触发JenkinsBuild

  • 相关阅读:
    2018最新php笔试题及答案(持续更新)
    快速上手模板制作
    春节期间小游戏同时在线人数最高达2800万人/小时
    公众平台新增修改文章错别字功能 每篇文章允许被修改一次仅限正文内五个字
    微信6.6.2版更新:支持两个账号一键切换
    小程序支持打开APP了 还有小程序的标题栏也可以自定义
    小程序发布重磅数据:日活跃用户数1.7亿、已上线小程序58万个,覆盖100万开发者、2300个第三方平台
    张小龙2018PRO版微信公开课演讲全文 透露2018微信全新计划
    除了跳一跳还有16款微信小游戏可以玩
    小游戏里潜藏着600亿的大市场
  • 原文地址:https://www.cnblogs.com/ifme/p/12881701.html
Copyright © 2011-2022 走看看