sonarqube-jenkins-config

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

     "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

上一篇:jenkins sonarqube 代码检测


下一篇:【代码质量管理工具】——sonar