azure-devopssonarqubeazure-pipelinessonarqube-scanazure-pipelines-build-task

Sonar-scanner failed after execute project builders on Azure DevOps pipeline


Context: I have a pipeline on Azure DevOps running on a self-hosted agent (deployed on kubernetes) and I am using the task 'Run Code Analysis' (right after the task 'Prepare Analysis Configuration'), from the SonarQube extension on Azure marketplace.

Problem: After configuring SonarQube for Azure DevOps, while running the 'Run Code Analysis' task, the pipeline produces the error:

INFO: SonarScanner 4.6.2.2472
INFO: Java 11.0.15 Private Build (64-bit)
INFO: Linux 5.4.17-2136.304.4.1.el7uek.x86_64 amd64
INFO: User cache: /root/.sonar/cache
INFO: Scanner configuration file: /azp/_work/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/5.6.1/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /azp/_work/1/s/sonar-project.properties
INFO: Analyzing on SonarQube server 9.4.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=112ms
INFO: Server id: 41D5D374-AYHzDcd0-Nvlhdy2JQfz
INFO: User cache: /root/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=40ms
INFO: Load/download plugins (done) | time=143ms
INFO: Process project properties
INFO: Process project properties (done) | time=1ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=3ms
WARN: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ClassRealm{javascript}-org.sonar.plugins.javascript.eslint.EslintBridgeServerImpl': Unsatisfied dependency expressed through constructor parameter 4; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'AnalysisTempFolder' defined in org.sonar.scanner.analysis.AnalysisTempFolderProvider: Unsatisfied dependency expressed through method 'provide' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DefaultInputProject' defined in org.sonar.scanner.scan.InputProjectProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.sonar.api.batch.fs.internal.DefaultInputProject]: Factory method 'provide' threw exception; nested exception is Validation of project failed:
  o To use the property "sonar.branch.name" and analyze branches, Developer Edition or above is required. See https://redirect.sonarsource.com/doc/branches.html for more information.
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 1.808s
INFO: Final Memory: 16M/237M
INFO: ------------------------------------------------------------------------
##[error]ERROR: Error during SonarScanner execution
ERROR: Validation of project failed:
  o To use the property "sonar.branch.name" and analyze branches, Developer Edition or above is required. See https://redirect.sonarsource.com/doc/branches.html for more information.
ERROR: Error during SonarScanner execution
ERROR: Validation of project failed:
##[error]ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
##[error]The process '/azp/_work/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/5.6.1/sonar-scanner/bin/sonar-scanner' failed with exit code 2
Finishing: Run Code Analysis

I've searched quite a bit and ran into branch analysis option being different between community and developer versions of SonarQube.

However, I have tried exec'ing into my azure agent and running sonar-scanner from there, and it works perfectly!

What I ran:

/azp/_work/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/5.6.1/sonar-scanner/bin/sonar-scanner -Dsonar.host.url=<our-server-url> -Dsonar.login=<sonarqube-generated-token> -Dsonar.projectKey=<the-project-key> -Dsonar.scm.disabled=true

Some of the output from that:

INFO: Scanner configuration file: /azp/_work/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/5.6.1/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.6.2.2472
INFO: Java 11.0.15 Private Build (64-bit)
INFO: Linux 5.4.17-2136.304.4.1.el7uek.x86_64 amd64
INFO: User cache: /root/.sonar/cache
INFO: Scanner configuration file: /azp/_work/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/5.6.1/sonar-scanner/conf/sonar-scanner.properties
...
INFO: Analysis total time: 1:11.998 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:13.344s
INFO: Final Memory: 46M/237M
INFO: ------------------------------------------------------------------------

I have no idea what to do to fix this...


Solution

  • The solution was related to the steps provided in these instructions. All I did was add those lines to the helm values, being careful to replace the version value, and reinstall Sonarqube. The sonarqube step is running without issues now.