Search code examples
sonarqubeazure-pipelines-build-tasksonarqube-msbuild-runner

On prem Sonar Server access issue from VSTS/TFS Online for Sonar analysis step


We are trying to add Sonar pre and post build steps in VSTS / TFS Online as explained in here and here . Both are pretty good documentation from Sonar and MS. here are steps followed
1. Exposed internal Sonar (hosted inside company firewall on prem) end point and we tested successfully with login credentials
2. Created end point in VSTS with special Sonar end point.

Out of TWO options -

  1. With Generic end point - If we chose to create with Generic end point which allows user name and pwd, Sonar Build step doesn't recognize end point in drop down , worst doesn't enable Save button :(

  2. With Sonar end point - So as to make it work , had to Create Sonar end point which allows token based access - created token for user , provided all project access to user ID

But somehow, Sonar begin analysis never completes but errors out after some time. From log messages (copied below), looks like its 401 Unauthorized issue

Is it possible to access on prem Sonar server from VSTS / TFS online for Sonar build step? Also not sure weather token based access is working or something else

FYI - installed Sonar extension for TFS online from marketplace

Thanks in advance

----------- Error Log ---------------
2017-01-25T12:14:16.9334904Z SonarQube Scanner for MSBuild 2.2
2017-01-25T12:14:16.9334904Z Default properties file was found at     D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\2.0.0\SonarQubeScannerMsBuild\SonarQube.Analysis.xml
2017-01-25T12:14:16.9334904Z Loading analysis properties from D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\2.0.0\SonarQubeScannerMsBuild\SonarQube.Analysis.xml
2017-01-25T12:14:16.9334904Z Pre-processing started.
2017-01-25T12:14:16.9334904Z Preparing working directories...
2017-01-25T12:14:16.9334904Z SonarQube Scanner for MSBuild 2.2
2017-01-25T12:14:16.9334904Z 12:14:16.484  Updating build integration targets...
2017-01-25T12:14:16.9334904Z 12:14:16.501  Fetching analysis configuration settings...
2017-01-25T12:14:17.4377059Z ##[error]
2017-01-25T12:14:17.5379198Z ##[error]Unhandled Exception: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
2017-01-25T12:14:17.5379198Z ##[error]at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
2017-01-25T12:14:17.5379198Z ##[error]at System.Net.WebClient.DownloadString(Uri address)
2017-01-25T12:14:17.5379198Z ##[error]at System.Net.WebClient.DownloadString(String address)
2017-01-25T12:14:17.5379198Z ##[error]at SonarQube.TeamBuild.PreProcessor.WebClientDownloader.Download(String url)

Solution

  • First, regarding the endpoint, it was previously only possible to use a Generic Endpoint but since v2 we decided to move to a specific SonarQube Endpoint and so decided to drop support of the generic one.

    We also decided to only support token based authentication because we strongly believe this is more secure than a username/password one.

    Last, based on the log and what you described I think your token has not been correctly copied into the SonarQube Endpoint. Depending on your browser it may have added a space at the end. You can test that your token is valid by running an analysis locally (follow this tutorial). If the begin part is successful you don't need to go further.

    Feel free to tell us if the token is correct so we can dig deeper.