3

I’m trying to integrate SonarQube with Azure Devops. I have done the configuration in the SonarQube administrator ( Administration > Configuration > General Settings > ALM Integrations , select the Azure DevOps tab, and click the Create configuration button) and setup the service connection in Azure Devops. Also configured the SonarScanner properties file.

sonar.projectkey= Project
sonar.projectName= Project name is given
sonar.login = token from SonarQube

Verified the Sonar-scanner using cmd command “sonar-scanner -h”. The sonar-scanner.bat file also has successfully executed. In Azure devops Build pipeline, have configured the branch - Prepare Analysis Configuration, Run Code Analysis and Publish Quality Gate Result. When we run the pipe it fails with the below error.

  ERROR: Not authorized. Please check the properties sonar.login and sonar.password.



 ERROR: Error during SonarScanner execution
    
ERROR: Not authorized. Please check the properties sonar.login and sonar.password.

INFO: ------------------------------------------------------------------------

##[error]ERROR:

ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

ERROR:

Below are the last lines of the log

“GET /batch/file?name=sonar-scanner-engine-shaded-9.0.1.46107-all.jar HTTP/1.1” 200 - “-” “ScannerCLI/4.6.1.2450” “AXtcvnCkoRmL3dzQAADB”



“GET /api/settings/values.protobuf HTTP/1.1” 401 - “-” “ScannerCLI/4.6.1.2450” “AXtcvnCkoRmL3dzQAADC”

Kindly help me with the above error. Thanks in Advance.

shaik idris
  • 31
  • 1
  • 2

1 Answers1

2

Finally, I made it working.

It turned out that you don't need to put the sonar.login = token into the sonar-project.properties.

What you need to do is:

  • to generate the token on the Sonar side;
  • place it to the service connection properties on Azure DevOps: in your Azure DevOps project, go to Settings > Service Connections and pick the service connection you use to connect to Sonar (if you don't have any, probably you should create one. It should be of type SonarQube). So in the properties of a service onnection of this type, there is a placeholder for a token, you won't miss it.
  • finally, if your service connection is named, say, SonarConnection, and you Sonar project key is My-Project, then your Azure pipeline will be looking like:
trigger:
- master
- staging
- dev

pool:
  vmImage: ubuntu-latest

steps:
- task: SonarQubePrepare@5
  inputs:
    SonarQube: 'SonarConnection'
    scannerMode: 'CLI'
    configMode: 'file'
    projectName: 'My Project'
    projectKey: 'My-Project'
- task: SonarQubeAnalyze@5
- task: SonarQubePublish@5
  inputs:
    pollingTimeoutSec: '300'

(I also use TLS connection to my SonarQube server with Let'sEncrypt certificates.)

Yury Kirienko
  • 1,810
  • 1
  • 22
  • 32