Error while to integrating Jenkins and Sonarqube for analysing my Angular project

Viewed 3163

I'm trying to integrate Jenkins and Sonarqube. I'm using the Sonarqube-Scanner plugin in jenkins. When I build the job, I get the following errors:-

  1. Failed to get Node.js version. No CSS files will be analyzed.
  2. Failed to get Node.js version. No TypeScript files will be analyzed. You can exclude TypeScript files from analysis with 'sonar.exclusions' property.

Any idea as to why this happens? I tried running the same job with a simple NodeJs project and it works fine.

Any help would be greatly appreciated, Thanks!

1 Answers

To perform sonar scan on Angular Project, you need to install typescript first. So, we need nodejs >=8 and npm installed. Check this post on How to install nodejs and npm in Jenkins. and also, How to integrate sonarqube in Jenkins

Sample Pipeline:

pipeline {
  agent any

  tools {nodejs "node_v10"}

  stages {
     stage('Git Pull') {
       steps {
          echo 'Code Checkout'
          }
        }
     stage('Install Typescript') {
        steps {
           sh 'npm install typescript'
            }
         }
     stage('Code scan Sonarqube') {
        steps {
          script {
       def scannerHome = tool 'sonarqube';
       withSonarQubeEnv("sonarqube-container") {
       sh """${tool("sonarqube")}/bin/sonar-scanner \
       -Dsonar.projectKey=test-node-js \
       -Dsonar.sources=. \
       -Dsonar.projectName=test-node-js \
       -Dsonar.projectVersion=1.0 """
           }
       } 
    }
         }
       }

Please change or include some other sonar analysis parameters if needed.

Visit to know more about how to analyse typescript code

Related