Analyse SQL Code with Sonar Qube

Must-share information (formatted with Markdown):

  • Developer Edition version 9.0
  • Analyse SQL Code
  • Added steps
  1. Prepare analysis on SonarQube
  2. Run Code Analysis
  3. Publish Quality Gate Result

We are using Redgate for building our SQL code. I am trying to add analysis with in CI builds to analyse the Sonar analysis on SQL code.

When I added above steps got this error:-

021-07-27T09:56:08.3623175Z ##[warning]Cmdlet parameter QueryBatchTimeout is not supported for SQL Change Automation projects. This option will be ignored.
2021-07-27T09:56:08.5029516Z Validating SQL Change Automation project D:\agents\03\_work\8785\s\Databases\Messaging\Messaging.sqlproj.
2021-07-27T09:56:27.2065162Z ##[warning]	Error: ERROR D:\agents\03\_work\8785\.sonarqube\bin\targets\SonarQube.Integration.targets(136,5): **SonarQube analysis is only supported with MSBuild 14 or later.**
2021-07-27T09:56:27.2065162Z Cleaning shadow database [sql_change_automation_a30a8549-4a75-4d5b-8c58-60ec587d1888]
2021-07-27T09:56:27.2065162Z Skipping Shadow clean; [sql_change_automation_a30a8549-4a75-4d5b-8c58-60ec587d1888] does not exist
2021-07-27T09:56:27.2377916Z ##[error]RedGate.Versioning.Automation.Shared.Errors.TerminatingException: Schema validation failed: 
2021-07-27T09:56:27.2377916Z    at RedGate.Versioning.Automation.MsBuild.MsBuildTaskRunner.PerformBuild(String projectPath, IDictionary`2 globalProperties)
2021-07-27T09:56:27.2377916Z    at RedGate.Versioning.Automation.Compare.Projects.ScaProjectBuilder.Build(ScaProjectPath scaProject, IDatabase database)
2021-07-27T09:56:27.2377916Z    at RedGate.Versioning.Automation.Compare.SchemaValidation.DiskBackedProjectValidator.ValidateProject(IProjectPath projectPath, IDatabase database, CreateDatabaseParameters createDatabaseParameters)
2021-07-27T09:56:27.2377916Z    at RedGate.Versioning.Automation.Compare.SchemaValidation.ProjectValidator.ValidateProject(String projectPath, CreateDatabaseParameters createDatabaseParameters)
2021-07-27T09:56:27.2377916Z    at RedGate.Versioning.Automation.PowerShell.Commands.InvokeDatabaseBuildCommandImpl.Process()
2021-07-27T09:56:27.2377916Z    at RedGate.Versioning.Automation.PowerShell.DlmAutomationCommandImpl`1.ProcessRecord()
2021-07-27T09:56:27.2377916Z    at RedGate.PowerShell.CommandBase`2.DelegateTo(Action doImplementation)
2021-07-27T09:56:27.2690157Z ##[error]Unable to process command '##vso[artifact.upload artifactname=Database Build Artifact;containerfolder=Database Build Artifact;]D:\agents\03\_work\8785\s\MessagingDataBase.20210727.2.nupkg' successfully. Please reference documentation (http://go.microsoft.com/fwlink/?LinkId=817296)
2021-07-27T09:56:27.2690157Z ##[error]Path not exist: D:\agents\03\_work\8785\s\MessagingDataBase.20210727.2.nupkg
2021-07-27T09:56:27.3627657Z ##[error]PowerShell script completed with 1 errors.
2021-07-27T09:56:27.3627657Z ##[section]Finishing: Build MessagingDataBase

Thanks
Sunil Bindra

Hi Sunil,

This part of your log is interesting

It implies that MSBuild is involved somewhere in here. Could you more fully describe your build/analysis process? Are you trying to analyze only T-SQL or C# as well?

 
Ann

Hi Ann

We are using Red gate for building SQL projects. Which is building .sqlproj. Each DB project has .sln file as well. All the projects contains different Scripts like static data, migration scripts etc.

Thanks
Sunil

Hi Sunil,

Could you provide your exact build and analysis commands?

 
Ann

Hi Ann

Thanks for your help I manage to resolve. We need to to download Sonar code guard to integrate it with Red Gate SQL Change Automation for running the analysis.

Code Analysis for SQL Server command line - SQL Code Analysis - Product Documentation (red-gate.com)

Thanks
Sunil Bindra

1 Like