FifthGearOnline
FifthGearOnline

Reputation: 60

401 Unauthorized error analyzing with TFS 2015 and SonarQube 5.6.1

We are using an On Premises TFS 2015 Update 2 server, using TFS Version Control. Currently we are running SonarQube 5.5 on our main analysis server and analysis is executing without issue on a daily basis. We are NOT using LDAP on the SonarQube server, and the everyone group has authorization to execute analysis.

However i upgraded my test server to SonarQube 5.6.1 in preparation for the updated FXCop rules with the correct categorization of the rules (bug, vulnerability, etc...). However , when I attempt to run analysis the task "Fetch the Quality Profile from SonarQube" fails with a (401) Unauthorized error. I have the console output from that task below.

I was able to find this change to version 5.6. Is this what is causing my authorization problem? https://jira.sonarsource.com/browse/SONAR-7640

When i review the SonarQube.Analysis.xml file that is automatically generated, the sonar.host.url, sonar.login and sonar.password entries are correct. The user it has in the file is an admin in sonarqube, and has rights to execute analysis.

I also ran across this on github. https://github.com/Microsoft/vsts-tasks/issues/1851

A new option was added to VSTS to resolve an issue with Sonar failing with a 401 Unauthorized error. However that appears to be an issue with the end of the analysis process because it could not create the summary report.

If i take my test server, and switch the windows service that is running BACK to my SonarQube 5.5 copy, it will work without any authorization errors.

The sonarqube windows service, and the TFS Build Agent are running as a user that is an administrator on both my test machine and a TFS Admin.

Failed Task Output:

Executing the powershell script: D:\Agent\tasks\SonarQubePreBuild\1.0.34\SonarQubePreBuild.ps1
SonarQube Scanner for MSBuild 1.1
Default properties file was found at D:\Agent\tasks\SonarQubePreBuild\1.0.34\MSBuild.SonarQube.Runner-1.1\SonarQube.Analysis.xml
Loading analysis properties from D:\Agent\tasks\SonarQubePreBuild\1.0.34\MSBuild.SonarQube.Runner-1.1\SonarQube.Analysis.xml
Pre-processing started.
Preparing working directories...
Checking for updates...
SonarQube Scanner for MSBuild Begin Step 2.1
Loading analysis properties from D:\Agent\tasks\SonarQubePreBuild\1.0.34\MSBuild.SonarQube.Runner-1.1\SonarQube.Analysis.xml
Updating build integration targets...
Fetching analysis configuration settings...
Unhandled Exception: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
  at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
  at System.Net.WebClient.DownloadString(Uri address)
  at System.Net.WebClient.DownloadString(String address)
  at SonarQube.TeamBuild.PreProcessor.WebClientDownloader.Download(String url)
  at SonarQube.TeamBuild.PreProcessor.SonarWebService.GetProperties(String projectKey, String projectBranch)
  at SonarQube.TeamBuild.PreProcessor.TeamBuildPreProcessor.FetchArgumentsAndRulesets(ISonarQubeServer server, ProcessedArgs args, TeamBuildSettings settings, IDictionary`2& serverSettings, AnalyzerSettings& analyzerSettings)
  at SonarQube.TeamBuild.PreProcessor.TeamBuildPreProcessor.DoExecute(ProcessedArgs args)
  at SonarQube.TeamBuild.PreProcessor.TeamBuildPreProcessor.Execute(String[] args)
  at SonarQube.TeamBuild.PreProcessor.Program.Main(String[] args)
Pre-processing succeeded.
System.Exception: Unexpected exit code received from batch file: 255
  at Microsoft.TeamFoundation.DistributedTask.Task.Internal.PowerShell.InvokeBatchScriptCmdlet.ProcessRecord()
  at System.Management.Automation.CommandProcessor.ProcessRecord()

Upvotes: 1

Views: 1155

Answers (1)

FifthGearOnline
FifthGearOnline

Reputation: 60

I was able to get this working by removing the user on my build agent service, and adding it again, but making sure the user id for the service was all lowercase letters. That is honestly all I did and now its working.

Upvotes: 2

Related Questions