Search code examples
sonarqubeazure-devopsasp.net-core-2.0vstest.console.exe

VSTS+ SonarQube + DotNetCore 2.0 + Unit Tests


Anyone know the right combination of VS Tasks, arguments and commandlines to get these 4 things to play nice together?

I can get SonarQube to do analysis on the code doing the following:

  • SonarQube Scanner for MSBuild - Begin Analysis
  • Visual Studio Build
  • SonarQube Scanner for MSBuild - End Analysis

But the Visual Studio Test task won't find any dotnetcore 2.0 test I write (tried MSTest and xUnit frameworks, and a whole host of arguments)

I can get dotnet build/test tasks to work, but I can't get SonarQube Scanner CLI to do anything but blow up with errors that start with

    2017-09-29T17:38:40.6401974Z ##[error]ERROR: Error during SonarQube Scanner execution
2017-09-29T17:38:40.6401974Z ##[error]java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.ProjectLock
2017-09-29T17:38:40.6401974Z ##[error]at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:71)

Looking for some suggestions on how to either get the VS-Task "Visual Studio Test" to run dotnetcore 2.0 built tests OR get the SonarQube CLI to play nice with VSTS hosted agents...

UPDATE : Instructions in the first answer got the build to work (thank you for the hint on how to get .NET Core 2.0 tests to run!! I couldn't find that framework key anywhere... SonarQube is now blowing up on the close.. Here is the log (with debugging) for the step from VSTS

==============================================================================
Task         : SonarQube  Scanner for MSBuild - End Analysis (new)
Description  : Complete the SonarQube analysis of your solution
Version      : 3.0.2
Author       : SonarSource
Help         : Version: 3.0.2. [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
Preparing task execution handler.
Executing the powershell script: d:\a\_tasks\SonarQubeScannerMsBuildEnd_6d01813a-9589-4b15-8491-8164aeb38055\3.0.2\SonarQubePostTest.ps1
PowerShellHandler.Execute - AddCommand(d:\a\_tasks\SonarQubeScannerMsBuildEnd_6d01813a-9589-4b15-8491-8164aeb38055\3.0.2\SonarQubePostTest.ps1)
PowerShellHandler.Execute - Invoke
Starting SonarQube PostBuild Step
Loading module from path 'C:\LR\mms\Services\Mms\Provisioner\TaskAgent\agents\2.123.0\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Common\Microsoft.TeamFoundation.DistributedTask.Task.Common.psd1'.
Loading module from path 'C:\LR\mms\Services\Mms\Provisioner\TaskAgent\agents\2.123.0\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Common\Microsoft.TeamFoundation.DistributedTask.Task.Common.psm1'.
Loading module from path 'C:\LR\mms\Services\Mms\Provisioner\TaskAgent\agents\2.123.0\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.LegacySDK.dll'.
Importing cmdlet 'Invoke-ResultPublisher'.
Importing cmdlet 'Publish-TestResults'.
Importing cmdlet 'Add-BuildArtifactLink'.
Importing cmdlet 'Add-BuildAttachment'.
Importing cmdlet 'Convert-String'.
Importing cmdlet 'Copy-BuildArtifact'.
Importing cmdlet 'Get-JavaDevelopmentKitPath'.
Importing cmdlet 'Get-MSBuildLocation'.
Importing cmdlet 'Get-ServiceEndpoint'.
Importing cmdlet 'Get-TaskVariable'.
Importing cmdlet 'Get-TfsClientCredentials'.
Importing cmdlet 'Get-ToolPath'.
Importing cmdlet 'Get-VisualStudioPath'.
Importing cmdlet 'Get-VssConnection'.
Importing cmdlet 'Invoke-Ant'.
Importing cmdlet 'Invoke-BatchScript'.
Importing cmdlet 'Invoke-Maven'.
Importing cmdlet 'Invoke-MSBuild'.
Importing cmdlet 'Invoke-Tool'.
Importing cmdlet 'Invoke-VSTest'.
Importing cmdlet 'Publish-BuildArtifact'.
Importing cmdlet 'Register-XamarinLicense'.
Importing cmdlet 'Unregister-XamarinLicense'.
Importing cmdlet 'Get-X509Certificate'.
Importing cmdlet 'Invoke-DeployTestAgent'.
Importing cmdlet 'Invoke-RunDistributedTests'.
Importing cmdlet 'Invoke-BlockEnvironment'.
Importing cmdlet 'Copy-FilesToAzureBlob'.
Importing cmdlet 'Copy-FilesToTargetMachine'.
Importing cmdlet 'Copy-ToAzureMachines'.
Importing cmdlet 'Remove-Environment'.
Importing cmdlet 'Remove-EnvironmentResources'.
Importing cmdlet 'Complete-EnvironmentOperation'.
Importing cmdlet 'Complete-EnvironmentResourceOperation'.
Importing cmdlet 'Complete-ResourceOperation'.
Importing cmdlet 'Get-Environment'.
Importing cmdlet 'Get-EnvironmentProperty'.
Importing cmdlet 'Get-EnvironmentResources'.
Importing cmdlet 'Get-ExternalIpAddress'.
Importing cmdlet 'Get-ParsedSessionVariables'.
Importing cmdlet 'Get-ProviderData'.
Importing cmdlet 'Invoke-EnvironmentOperation'.
Importing cmdlet 'Invoke-ResourceOperation'.
Importing cmdlet 'Invoke-PsOnRemote'.
Importing cmdlet 'New-OperationLog'.
Importing cmdlet 'Copy-FilesToRemote'.
Importing cmdlet 'Register-Environment'.
Importing cmdlet 'Register-EnvironmentDefinition'.
Importing cmdlet 'Register-Provider'.
Importing cmdlet 'Register-ProviderData'.
Importing cmdlet 'Invoke-UnblockEnvironment'.
Importing cmdlet 'Add-TaskIssue'.
Importing cmdlet 'Complete-Task'.
Importing cmdlet 'Find-Files'.
Importing cmdlet 'Get-LocalizedString'.
Importing cmdlet 'Set-TaskProgress'.
Importing cmdlet 'Set-TaskVariable'.
Importing cmdlet 'Write-TaskDetail'.
Importing cmdlet 'Enable-CodeCoverage'.
Importing cmdlet 'Publish-CodeCoverage'.
Exporting cmdlet 'Add-TaskIssue'.
Exporting cmdlet 'Complete-Task'.
Exporting cmdlet 'Find-Files'.
Exporting cmdlet 'Get-LocalizedString'.
Exporting cmdlet 'Set-TaskProgress'.
Exporting cmdlet 'Set-TaskVariable'.
Exporting cmdlet 'Write-TaskDetail'.
Importing cmdlet 'Add-TaskIssue'.
Importing cmdlet 'Complete-Task'.
Importing cmdlet 'Find-Files'.
Importing cmdlet 'Get-LocalizedString'.
Importing cmdlet 'Set-TaskProgress'.
Importing cmdlet 'Set-TaskVariable'.
Importing cmdlet 'Write-TaskDetail'.
Importing cmdlet 'Invoke-ResultPublisher'.
Importing cmdlet 'Publish-TestResults'.
Importing cmdlet 'Add-BuildArtifactLink'.
Importing cmdlet 'Add-BuildAttachment'.
Importing cmdlet 'Convert-String'.
Importing cmdlet 'Copy-BuildArtifact'.
Importing cmdlet 'Get-JavaDevelopmentKitPath'.
Importing cmdlet 'Get-MSBuildLocation'.
Importing cmdlet 'Get-ServiceEndpoint'.
Importing cmdlet 'Get-TaskVariable'.
Importing cmdlet 'Get-TfsClientCredentials'.
Importing cmdlet 'Get-ToolPath'.
Importing cmdlet 'Get-VisualStudioPath'.
Importing cmdlet 'Get-VssConnection'.
Importing cmdlet 'Invoke-Ant'.
Importing cmdlet 'Invoke-BatchScript'.
Importing cmdlet 'Invoke-Maven'.
Importing cmdlet 'Invoke-MSBuild'.
Importing cmdlet 'Invoke-Tool'.
Importing cmdlet 'Invoke-VSTest'.
Importing cmdlet 'Publish-BuildArtifact'.
Importing cmdlet 'Register-XamarinLicense'.
Importing cmdlet 'Unregister-XamarinLicense'.
Importing cmdlet 'Get-X509Certificate'.
Importing cmdlet 'Invoke-DeployTestAgent'.
Importing cmdlet 'Invoke-RunDistributedTests'.
Importing cmdlet 'Invoke-BlockEnvironment'.
Importing cmdlet 'Copy-FilesToAzureBlob'.
Importing cmdlet 'Copy-FilesToTargetMachine'.
Importing cmdlet 'Copy-ToAzureMachines'.
Importing cmdlet 'Remove-Environment'.
Importing cmdlet 'Remove-EnvironmentResources'.
Importing cmdlet 'Complete-EnvironmentOperation'.
Importing cmdlet 'Complete-EnvironmentResourceOperation'.
Importing cmdlet 'Complete-ResourceOperation'.
Importing cmdlet 'Get-Environment'.
Importing cmdlet 'Get-EnvironmentProperty'.
Importing cmdlet 'Get-EnvironmentResources'.
Importing cmdlet 'Get-ExternalIpAddress'.
Importing cmdlet 'Get-ParsedSessionVariables'.
Importing cmdlet 'Get-ProviderData'.
Importing cmdlet 'Invoke-EnvironmentOperation'.
Importing cmdlet 'Invoke-ResourceOperation'.
Importing cmdlet 'Invoke-PsOnRemote'.
Importing cmdlet 'New-OperationLog'.
Importing cmdlet 'Copy-FilesToRemote'.
Importing cmdlet 'Register-Environment'.
Importing cmdlet 'Register-EnvironmentDefinition'.
Importing cmdlet 'Register-Provider'.
Importing cmdlet 'Register-ProviderData'.
Importing cmdlet 'Invoke-UnblockEnvironment'.
Importing cmdlet 'Add-TaskIssue'.
Importing cmdlet 'Complete-Task'.
Importing cmdlet 'Find-Files'.
Importing cmdlet 'Get-LocalizedString'.
Importing cmdlet 'Set-TaskProgress'.
Importing cmdlet 'Set-TaskVariable'.
Importing cmdlet 'Write-TaskDetail'.
Importing cmdlet 'Enable-CodeCoverage'.
Importing cmdlet 'Publish-CodeCoverage'.
Exporting cmdlet 'Add-BuildArtifactLink'.
Exporting cmdlet 'Add-BuildAttachment'.
Exporting cmdlet 'Convert-String'.
Exporting cmdlet 'Copy-BuildArtifact'.
Exporting cmdlet 'Get-JavaDevelopmentKitPath'.
Exporting cmdlet 'Get-MSBuildLocation'.
Exporting cmdlet 'Get-ServiceEndpoint'.
Exporting cmdlet 'Get-TaskVariable'.
Exporting cmdlet 'Get-TfsClientCredentials'.
Exporting cmdlet 'Get-ToolPath'.
Exporting cmdlet 'Get-VisualStudioPath'.
Exporting cmdlet 'Get-VssConnection'.
Exporting cmdlet 'Invoke-Ant'.
Exporting cmdlet 'Invoke-BatchScript'.
Exporting cmdlet 'Invoke-Maven'.
Exporting cmdlet 'Invoke-MSBuild'.
Exporting cmdlet 'Invoke-Tool'.
Exporting cmdlet 'Invoke-VSTest'.
Exporting cmdlet 'Publish-BuildArtifact'.
Exporting cmdlet 'Register-XamarinLicense'.
Exporting cmdlet 'Unregister-XamarinLicense'.
Exporting cmdlet 'Get-X509Certificate'.
Processed: ##vso[task.setprogress value=-1;]
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.Internal.BootstrapperPath = D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\MSBuild.SonarQube.Runner.exe
bootstrapperPath: D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\MSBuild.SonarQube.Runner.exe
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.ServerUsername = ********
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.ServerPassword =
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.DbUsername =
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.DbPassword =
Running batch script.
Path: D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\MSBuild.SonarQube.Runner.exe
Arguments: end /d:sonar.login=********
WorkingFolder:
Entering ProcessWrapper.CreateStartInfo
workingFolder = D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild
filename = cmd.exe
arguments = /c ""D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\MSBuild.SonarQube.Runner.exe" end /d:sonar.login=********"
Leaving ProcessWrapper.CreateStartInfo
ProcessWrapper.Start - enter
ProcessWrapper.Start - starting process
ProcessWrapper.Start - process started
ProcessWrapper.Start - leave
Unhandled Exception: System.ComponentModel.Win32Exception: The directory name is invalid
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at SonarQube.Common.ProcessRunner.Execute(ProcessRunnerArguments runnerArgs)
at SonarQube.TeamBuild.Integration.CoverageReportConverter.ConvertBinaryToXml(String converterExeFilePath, String inputBinaryFilePath, String outputXmlFilePath, ILogger logger)
at SonarQube.TeamBuild.Integration.CoverageReportConverter.ConvertToXml(String inputFilePath, String outputFilePath, ILogger logger)
at SonarQube.TeamBuild.Integration.CoverageReportProcessorBase.ProcessBinaryCodeCoverageReport(String binaryCoverageFilePath)
at SonarQube.TeamBuild.Integration.CoverageReportProcessorBase.ProcessCoverageReports()
at SonarQube.TeamBuild.PostProcessor.CoverageReportProcessor.ProcessCoverageReports()
at SonarQube.TeamBuild.PostProcessor.MSBuildPostProcessor.Execute(String[] args, AnalysisConfig config, ITeamBuildSettings settings)
at SonarQube.Bootstrapper.BootstrapperClass.PostProcess()
at SonarQube.Bootstrapper.BootstrapperClass.Execute()
at SonarQube.Bootstrapper.Program.Execute(String[] args, ILogger logger)
at SonarQube.Bootstrapper.Program.Main(String[] args)
at SonarQube.Old.Bootstrapper.Program.Main(String[] args)
SonarQube Scanner for MSBuild 3.0.2
Default properties file was found at D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\SonarQube.Analysis.xml
Loading analysis properties from D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\SonarQube.Analysis.xml
Post-processing started.
16:18:14.455  Fetching code coverage report information from TFS...
16:18:14.456  Attempting to locate a test results (.trx) file...
16:18:14.594  Looking for TRX files in: d:\a\1\TestResults, d:\a\1\s\TestResults
16:18:14.594  Located a test results file: d:\a\1\s\TestResults\buildguest_FACTORYVM-AZ203_2017-10-02_16_18_07.trx
System.Exception: Unexpected exit code received from batch file: -532462766
Processed: ##vso[task.logissue type=error;]System.Exception: Unexpected exit code received from batch file: -532462766
   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.InvokeBatchScriptCmdlet.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
The build was not triggered by a Pull Request, not processing code analysis comments
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.Internal.IncludeFullReport = true
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.Internal.ServerVersion =
Calling InvokeGetRestMethod "/api/server/version"
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.HostUrl = http://13.65.82.206/
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.ServerUsername = ********
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.ServerPassword =
GET http://13.65.82.206/api/server/version with 0-byte payload
received 11-byte response of content type text/plain
Processed: ##vso[task.setvariable variable=MSBuild.SonarQube.Internal.ServerVersion;]6.5.0.27846
The SonarQube server version is 6.5.0.27846
Waiting on the SonarQube server to finish processing in order to determine the quality gate status.
Invoke - Get-TaskVariable cmdlet
Variable read: Agent.BuildDirectory = d:\a\1
Could not find the task details file at d:\a\1\.sonarqube\out\.sonar\report-task.txt
System.Management.Automation.RuntimeException: Cannot determine if the analysis has finished. Possible cause: your SonarQube server version is lower than 5.3 - for more details see https://go.microsoft.com/fwlink/?LinkId=722407 ---> System.Management.Automation.RuntimeException: Cannot determine if the analysis has finished. Possible cause: your SonarQube server version is lower than 5.3 - for more details see https://go.microsoft.com/fwlink/?LinkId=722407
Processed: ##vso[task.logissue type=error;]System.Management.Automation.RuntimeException: Cannot determine if the analysis has finished. Possible cause: your SonarQube server version is lower than 5.3 - for more details see https://go.microsoft.com/fwlink/?LinkId=722407 ---> System.Management.Automation.RuntimeException: Cannot determine if the analysis has finished. Possible cause: your SonarQube server version is lower than 5.3 - for more details see https://go.microsoft.com/fwlink/?LinkId=722407
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at Microsoft.TeamFoundation.DistributedTask.Handlers.LegacyVSTSPowerShellHost.VSTSPowerShellHost.Main(String[] args)
LegacyVSTSPowerShellHost.exe completed with return code: -1.

Solution

  • Refer to these steps to run DotNet Core Test through Visual Studio Test task:

    1. Add Visual Studio Test task
    2. Select Specific location option with C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform value in Execution options section
    3. Specify /framework:".NETCoreApp,Version=v2.0" in Other console options