sonarqube-jenkins-config

梦想的初衷 提交于 2021-01-19 06:36:49

Sonar Config

  1. .Jenkinsfile config

     stage('SonarQube analysis') {
         steps {
           script {
             scannerHome = tool 'SonarScanner4';
           }
           withSonarQubeEnv('SonarQube') {
             sh "${scannerHome}/bin/sonar-scanner"
           }
         }
       }
    
  2. sonar-project.properties

     sonar.projectBaseDir=test-app // app dir
     sonar.projectName=test-app
     sonar.projectKey=test-app
     sonar.projectVersion=1.0
     sonar.sourceEncoding=UTF-8
     sonar.language=js
     sonar.sources=src
     sonar.tests=test
     sonar.exclusions=test/**,node_modules/**,build/**,**/less/**,**/config/**,**/config.js,**/imgs/** // files not to test
     sonar.test.inclusions=test/shared/*.js,test/components/**/*.js // files to test
     sonar.javascript.lcov.reportPaths=coverage/lcov.info //coverage path
     sonar.testExecutionReportPaths=coverage/test-report.xml  //unit test path		
    
  3. package.json

              "eslint-plugin-sonarjs": "^0.3.0",
     "jest-sonar-reporter": "^2.0.0",
    
     "jestSonar": {
     "reportPath": "coverage", // same with path in  sonar-project.properties file
     "reportFile": "test-report.xml", // same with path in  sonar-project.properties file
     "sonar56x": true // to get coverage data for sonarQ 5.6.*
    

    }

  4. jest.config.js

     module.exports = Object.assign(jestConfig, {
      coverageThreshold: {
         global: {
           branches: 95,
           functions: 95,
           lines: 95,
           statements: 95,
         },
     },
       testResultsProcessor: 'jest-sonar-reporter',
     });
    
  5. .eslintrc

     {
       "parser": "babel-eslint",
       "extends": [ "plugin:sonarjs/recommended"],
       "plugins": ["sonarjs"],
       "rules": {
         "eol-last": ["error", "always"],
         "sonarjs/cognitive-complexity": ["error", 25],
         "sonarjs/no-duplicate-string": "off",
         "sonarjs/no-identical-functions": "off"
       }
     }		
    

fiels:

  1. jest-sonar-reporter

  2. eslint-plugin-sonarjs

  3. sonarqube file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!