1
votes

Checkout of front end & back end code in multiple folders within jenkin's ${WORKSPACE} , as shown below

enter image description here

Frontend code is written in Angular(TypeScript) and built using npm

Backend code is written in Java and built using gradlew


Referring documentation for SonarQube scanner with Jenkins, here. I got the below piece of code to run SonarQube scanner for multi-language(angular & java) static code analysis

node {
  stage('SCM') {
    git 'https://github.com/foo/bar.git'
  }
  stage('SonarQube analysis') {
    // requires SonarQube Scanner 2.8+
    def scannerHome = tool 'SonarQube Scanner 2.8';
    withSonarQubeEnv('My SonarQube Server') {
      sh "${scannerHome}/bin/sonar-scanner"
    }
  }
}

As per below screenshot, below is the sonar scanner installation in jenkins:

enter image description here

1) Does def scannerHome = tool 'abc_install'; grab the SonarQube scanner configured in Jenkins?

2) Does sh "${scannerHome}/bin/sonar-scanner" perform static code analysis for both TypeScript & Java? in front-end-code & backend-code folder

1

1 Answers

1
votes

Please see answers:

1) Of course. In Jenkins you can configure many SonarQube scanners with different versions, and with construction def scannerHome = tool '<scanner name, configured in Jenkins>' you may grab any scanner your code need

2) Yes, it will. But, I'd recommend to split backend and frontend and specify language for each part. Also, I'd remove folders with with '@tmp' from static code scan. Please see list of parameters that can be added to scanner here: https://docs.sonarqube.org/latest/analysis/analysis-parameters/

Small example for backend:

${scannerHome}/bin/sonar-scanner \
                                -Dsonar.projectKey=project-${ENVIRONMENT} \
                                -Dsonar.sources=portal,common \
                                -Dsonar.java.binaries=portal,common \
                                -Dsonar.java.libraries=/**/*.jar \
                                -Dsonar.exclusions=portal/src/test/**,portal/src/intest/** \
                                -Dsonar.coverage.jacoco.xmlReportPaths=portal/build/reports/jacoco/test/jacocoTestReport.xml