How to have frontend + backend sonar scan results displayed together on a single project

Hi,

We have a azure repo containing both frontend and backend test cases. We have created a project based on azure repo on sonarqube portal.I have created a azure pipeline wherein it runs test cases for both frontend and backend in stages. Pipeline run frontend stage(run unit test + code coverage + sonar scan) and then same backend(.net unt test cases) while backend stage runs I can see the result published for frontend on sonarqube portal but when backend stage is completed, front end test and sonar scan data is overridden by backend. Is it possible to hold front end + backend scan data together on sonarqube portal?

Here is the snipped of code that I am using:

jobs:
      - job: Running_frontend_unit
        displayName: Running frontend Unit 
        pool:
          #vmImage: windows-latest

        steps:
          - checkout: self

          - task: SonarQubePrepare@5
            displayName: Prepare SonarQube analysis
            inputs:
              SonarQube: 'YYYYYYYYYYY'
              scannerMode: 'CLI'
              configMode: 'manual'
              cliProjectKey: 'XXXXXXXXXXX'
              cliSources: 'sc'
              extraProperties: |
                # Additional properties that will be passed to the scanner, 
                # Put one key=value per line, example:
                # sonar.exclusions=**/*.bin
                sonar.tests=sc
                sonar.sourceEncoding=UTF-8
                sonar.test.inclusions=**/*.spec.js
                sonar.testExecutionReportPaths=sc/coverage/test-reporter.xml
                sonar.javascript.lcov.reportPaths=sc/coverage/lcov.info

          - task: NodeTool@0
            displayName: Install Node Tool
            inputs:
              versionSource: 'spec'
              versionSpec: '14.x'

          - task: Npm@1
            displayName: npm install
            inputs:
              command: 'install'
              workingDir: 'sc/'
      
          - task: Npm@1
            displayName: npm run test
            inputs:
              command: 'custom'
              workingDir: 'sc/'
              customCommand: 'run test'
        

          - task: PublishTestResults@2
            displayName: 'Publishing test results'
            condition: succeededOrFailed()
            inputs:
              testResultsFormat: 'JUnit'
              testResultsFiles: '**/junit.xml'


          - task: PublishCodeCoverageResults@1
            displayName: 'Publish code coverage results'
            condition: succeededOrFailed()
            inputs:
              codeCoverageTool: Cobertura
              summaryFileLocation: $(System.DefaultWorkingDirectory)/sc/coverage/cobertura-coverage.xml
          
          - task: SonarQubeAnalyze@5
            inputs:
              jdkversion: 'JAVA_HOME_17_X64'
            displayName: Run Code Analysis

          - task: SonarQubePublish@5
            displayName: Publish Quality Gate Result





  ###############################################################################
  ############## BACKEND- RUN .NET UNIT TESTS & SONARQUBE TESTS #################
  ###############################################################################

  - stage: Running_Backend_Unit_Tests
    displayName: "🚀 Running Backend Unit Tests 🚀"
    variables:
      - group: "BUILD-OneDigital-SC-Variable-Sonarqube"

    jobs:
      - job: Running_backend_unit_tests
        displayName: Running Backend Unit Tests
        pool:
          #vmImage: windows-latest
        timeoutInMinutes: 0  
        steps:
          - checkout: self
            persistCredentials: true

          - task: SonarQubePrepare@5
            displayName: Prepare SonarQube analysis
            inputs:
              SonarQube: YYYYYYYYY
              projectKey: XXXXXXXXXX
              projectName: sonarproject
              extraProperties: "# Additional properties that will be passed to the scanner, \n# Put one key=value per line, example:\n# sonar.exclusions=**/*.bin\n"

          - task: NuGetToolInstaller@1
            displayName: Download latest version of NuGet.exe
            inputs:
              checkLatest: true

          - task: NuGetCommand@2
            displayName: NuGet restore
            inputs:
              feedsToUse: config
              nugetConfigPath: sc/NuGet.config

          - task: VSBuild@1
            displayName: Build solution **\.sln
            continueOnError: True
            inputs:
              solution: '**\.sln'
              configuration: Debug
              maximumCpuCount: true

          - task: VSTest@2
            displayName: VsTest - testAssemblies
            inputs:
              codeCoverageEnabled: true
              runInParallel: true

          - task: SonarQubeAnalyze@5
            displayName: Run Code Analysis

          - task: SonarQubePublish@5
            displayName: Publish Quality Gate Result

Hey there.

You’ll need to include your frontend (JS) files in your backend (.NET) analysis. Take a look at this section of the documentation.

Hi Colin,

We tried and included JS files in our backend solution. We have VueJS+JS as part of our front end code but implementing the solution offered by you only showing vuejs results along with .cs and not .JS files.
Can you please suggest how to get this done?

You’ll have to provide more details about what solution you finally implemented, and log files from your analysis where the JS files aren’t included as expected.

Hi Colin, I have added below files to visual studio solution file.

    <Content Include="Scripts\vue\Components\Steps\CustomerAddressDelivery.vue" />

  <Content Include="Scripts\helper\Core-Captcha.js" />
    <Content Include="Scripts\helper\Core-DeviceSelector.js" />

Sonar scans is taking “CustomerAddressDelivery.vue” in to consideration but not .JS files.
Below is my azure pipeline code:

- task: SonarQubePrepare@5
            displayName: Prepare SonarQube analysis
            inputs:
              SonarQube: 'XXXXXXXX'
              scannerMode: 'MSBuild'
              projectKey: 'XXXXXX'
              projectName: 'XXXXXXXXX'
              extraProperties: |
                # Additional properties that will be passed to the scanner, 
                # Put one key=value per line, example:
                # sonar.exclusions=**/*.bin
                # sonar.sources=sc
                # sonar.sourceEncoding=UTF-8

          - task: NuGetToolInstaller@1
            displayName: Download latest version of NuGet.exe
            inputs:
              checkLatest: true

          - task: NuGetCommand@2
            displayName: NuGet restore
            inputs:
              feedsToUse: config
              nugetConfigPath: sc/NuGet.config

          - task: VSBuild@1
            displayName: Build solution **\abc.sln
            continueOnError: True
            inputs:
              solution: '**\abc.sln'
              configuration: Debug
              maximumCpuCount: true

          - task: VSTest@2
            displayName: VsTest - testAssemblies
            inputs:
              codeCoverageEnabled: true
              runInParallel: true

          - task: SonarQubeAnalyze@5
            inputs:
              jdkversion: 'JAVA_HOME_17_X64'
            displayName: Run Code Analysis

          - task: SonarQubePublish@5
            displayName: Publish Quality Gate Result

Below is the error that I am getting at “RUn code analysis” task

ERROR: Node.js not found in PATH. PATH value was: C:\a\_tool\NuGet\6.9.1\x64;C:\agent\externals\git\cmd;C:\agent\externals\git\mingw64\bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Users\AzDevOps\AppData\Local\Microsoft\WindowsApps
##[error]org.sonar.plugins.javascript.nodejs.NodeCommandException: Node.js not found in PATH. PATH value was: C:\a\_tool\NuGet\6.9.1\x64;C:\agent\externals\git\cmd;C:\agent\externals\git\mingw64\bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Users\AzDevOps\AppData\Local\Microsoft\WindowsApps
	at org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.locateNodeOnWindows(NodeCommandBuilderImpl.java:312)
	at org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.locateNode(NodeCommandBuilderImpl.java:256)
	at org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.retrieveNodeExecutable(NodeCommandBuilderImpl.java:245)
org.sonar.plugins.javascript.nodejs.NodeCommandException: Node.js not found in PATH. PATH value was: C:\a\_tool\NuGet\6.9.1\x64;C:\agent\externals\git\cmd;C:\agent\externals\git\mingw64\bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Users\AzDevOps\AppData\Local\Microsoft\WindowsApps
	at org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.locateNodeOnWindows(NodeCommandBuilderImpl.java:312)
	at org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.locateNode(NodeCommandBuilderImpl.java:256)
	at org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.retrieveNodeExecutable(NodeCommandBuilderImpl.java:245)
##[error]at org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.build(NodeCommandBuilderImpl.java:152)
	at org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.build(NodeCommandBuilderImpl.java:152)
##[error]at org.sonar.plugins.javascript.bridge.BridgeServerImpl.initNodeCommand(BridgeServerImpl.java:263)
	at org.sonar.plugins.javascript.bridge.BridgeServerImpl.startServer(BridgeServerImpl.java:192)
	at org.sonar.plugins.javascript.bridge.BridgeServerImpl.initNodeCommand(BridgeServerImpl.java:263)
	at org.sonar.plugins.javascript.bridge.BridgeServerImpl.startServer(BridgeServerImpl.java:192)
##[error]at org.sonar.plugins.javascript.bridge.BridgeServerImpl.startServerLazily(BridgeServerImpl.java:303)
	at org.sonar.plugins.javascript.bridge.BridgeServerImpl.startServerLazily(BridgeServerImpl.java:303)
##[error]at org.sonar.plugins.javascript.bridge.AbstractBridgeSensor.execute(AbstractBridgeSensor.java:72)
	at org.sonar.plugins.javascript.bridge.AbstractBridgeSensor.execute(AbstractBridgeSensor.java:72)
##[error]at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
##[error]at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
##[error]at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:61)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:61)
INFO: Hit the cache for 0 out of 0

What version of SonarQube are you using?

We are using * Developer Edition

  • Version 10.3 (build 82913)

Thanks.

This particular issue probably fixes itself with SonarQube v10.4, where NodeJS is embedded in SonarQube (rather than relying on finding one in your environment). Can you upgrade?

Ok. I will try to upgrade and get back to you.