Good Morning Ann,
Thank you very much for the reply.
I have tried this, but am still getting some very strange and extremely frustrating issues.
I am going to try and outline the context here and what I have done.
Essentially, we have two projects that we are going to be analysing with SonarQube. I have been working on the bigger and more complex of the two, but to make things easier and to take out any other variables, I have switched to working on the other project which is a much smaller ASP.NET MVC project built on .net 8.0.
I have tried to detail the issues I have had with every step of trying to get SonarQube to work and I will also add a .zip file here with all of my logs for each iteration.
Iteration 1 - As per my original message, we get a java.lang.OutOfMemoryError: Java heap space error. Below is the Azure Devops Pipeline YAML code that was used when this occurred:-
# =============================================================================================
# SONARQUBE CONFIGURATION
# =============================================================================================
- task: SonarQubePrepare@7
displayName: "Prepare Analysis on SonarQube"
condition: eq('${{ parameters.runAnalysis }}', true)
env:
SONAR_SCANNER_OPTS: "-Xmx2048m"
inputs:
SonarQube: 'SonarQube'
scannerMode: 'dotnet'
dotnetScannerVersion: '10.1.2.114627'
projectKey: 'cbs-ops_DriverWebsite_815157f7-b691-4e43-8a8c-fc7edd5339b7'
projectName: 'DriverWebsite'
extraProperties: |
sonar.projectVersion=$(assemblyVersionNumber)
sonar.verbose=true
sonar.exclusions=**/*.sql,**/bin/**/*,**/obj/**/*,**/.git/**
sonar.branch.name=$(DriverWebsiteRepoRef)
# OTHER CODE HERE.....
# =============================================================================================
# APPLICATION COMPILATION
# =============================================================================================
# Build and publish the application using the .NET CLI
- task: DotNetCoreCLI@2
displayName: "Build ${{ parameters.applicationName }}"
env:
PostSharpLicense: $(postSharpLicenseKey)
inputs:
command: "publish"
publishWebProjects: false
projects: "$(Build.SourcesDirectory)/$(ExtractRepoNames.CleanDriverWebsiteRepoName)/${{ parameters.applicationName }}.sln"
zipAfterPublish: false
modifyOutputPath: false
workingDirectory: "$(Build.SourcesDirectory)/$(ExtractRepoNames.CleanDriverWebsiteRepoName)/"
platform: ${{ parameters.buildPlatform }}
arguments: "--no-restore --configuration ${{ parameters.buildConfiguration }} --output $(Build.ArtifactStagingDirectory)"
script: |
echo "Building application..."
echo "Application Name: ${{ parameters.applicationName }}"
echo "Build Configuration: ${{ parameters.buildConfiguration }}"
echo "Build Platform: ${{ parameters.buildPlatform }}"
echo "Output Directory: $(Build.ArtifactStagingDirectory)"
# =============================================================================================
# CODE ANALYSIS
# =============================================================================================
# Run the SonarQube analysis on the built code (only on scheduled builds)
- task: SonarQubeAnalyze@7
displayName: "Run Code Analysis With SonarQube"
condition: eq('${{ parameters.runAnalysis }}', true)
inputs:
jdkversion: 'JAVA_HOME_17_X64'
# Publish the analysis results to SonarQube and check the quality gate (only on scheduled builds)
- task: SonarQubePublish@7
displayName: "Publish Quality Gate Result To SonarQube"
condition: eq('${{ parameters.runAnalysis }}', true)
inputs:
pollingTimeoutSec: '300'
Next, I increase the heap space and got an error ā##[error]Not inside a Git work tree: /home/vsts/work/1/sā. Below is the Azure DevOps YAM Pipeline code when this error occurred.
# =============================================================================================
# SONARQUBE CONFIGURATION
# =============================================================================================
- task: SonarQubePrepare@7
displayName: "Prepare Analysis on SonarQube"
condition: eq('${{ parameters.runAnalysis }}', true)
env:
SONAR_SCANNER_OPTS: "-Xmx4096m"
inputs:
SonarQube: 'SonarQube'
scannerMode: 'dotnet'
projectKey: 'cbs-ops_DriverWebsite_815157f7-b691-4e43-8a8c-fc7edd5339b7'
projectName: 'DriverWebsite'
organization: 'Car Benefit Solutions Limited'
extraProperties: |
sonar.projectVersion=$(assemblyVersionNumber)
sonar.scm.provider=git
#sonar.verbose=true
sonar.exclusions=**/bin/**/*,**/obj/**/*
sonar.branch.name=$(DriverWebsiteRepoRef)
sonar.sourceEncoding=UTF-8
# =============================================================================================
# APPLICATION COMPILATION
# =============================================================================================
# Build and publish the application using the .NET CLI
- task: DotNetCoreCLI@2
displayName: "Build ${{ parameters.applicationName }}"
env:
PostSharpLicense: $(postSharpLicenseKey)
inputs:
command: "build"
publishWebProjects: false
projects: "$(Build.SourcesDirectory)/$(ExtractRepoNames.CleanDriverWebsiteRepoName)/${{ parameters.applicationName }}.sln"
zipAfterPublish: false
modifyOutputPath: false
workingDirectory: "$(Build.SourcesDirectory)/$(ExtractRepoNames.CleanDriverWebsiteRepoName)/"
platform: ${{ parameters.buildPlatform }}
arguments: "--no-restore --configuration ${{ parameters.buildConfiguration }} --output $(Build.ArtifactStagingDirectory)"
script: |
echo "Building application..."
echo "Application Name: ${{ parameters.applicationName }}"
echo "Build Configuration: ${{ parameters.buildConfiguration }}"
echo "Build Platform: ${{ parameters.buildPlatform }}"
echo "Output Directory: $(Build.ArtifactStagingDirectory)"
# =============================================================================================
# CODE ANALYSIS
# =============================================================================================
# Run the SonarQube analysis on the built code (only on scheduled builds)
- task: SonarQubeAnalyze@7
displayName: "Run Code Analysis With SonarQube"
condition: eq('${{ parameters.runAnalysis }}', true)
env:
SONAR_SCANNER_OPTS: "-Xmx4096m"
inputs:
jdkversion: 'JAVA_HOME_17_X64'
# Publish the analysis results to SonarQube and check the quality gate (only on scheduled builds)
- task: SonarQubePublish@7
displayName: "Publish Quality Gate Result To SonarQube"
condition: eq('${{ parameters.runAnalysis }}', true)
inputs:
pollingTimeoutSec: '300'
I then tried to make sure that I was really specific about the source location, and adding the sonar.projectBaseDire and sonar.src parameters. After this I get the following error āFile src/Cbs.Website.MVC/.vscode/launch.json canāt be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test filesā. Below is the Azure DevOps YAM Pipeline code when this error occurred.
# =============================================================================================
# SONARQUBE CONFIGURATION
# =============================================================================================
- task: SonarQubePrepare@7
displayName: "Prepare Analysis on SonarQube"
condition: eq('${{ parameters.runAnalysis }}', true)
env:
SONAR_SCANNER_OPTS: "-Xmx2048m"
inputs:
SonarQube: 'SonarQube'
scannerMode: 'dotnet'
projectKey: 'cbs-ops_DriverWebsite_815157f7-b691-4e43-8a8c-fc7edd5339b7'
projectName: 'DriverWebsite'
organization: 'Car Benefit Solutions Limited'
extraProperties: |
sonar.projectBaseDir=$(Build.SourcesDirectory)/$(ExtractRepoNames.CleanDriverWebsiteRepoName)
sonar.sources=src
sonar.projectVersion=$(assemblyVersionNumber)
sonar.scm.provider=git
#sonar.verbose=true
sonar.exclusions=**/bin/**/*,**/obj/**/*
sonar.branch.name=$(DriverWebsiteRepoRef)
sonar.sourceEncoding=UTF-8
# =============================================================================================
# APPLICATION COMPILATION
# =============================================================================================
# Build and publish the application using the .NET CLI
- task: DotNetCoreCLI@2
displayName: "Build ${{ parameters.applicationName }}"
env:
PostSharpLicense: $(postSharpLicenseKey)
inputs:
command: "build"
publishWebProjects: false
projects: "$(Build.SourcesDirectory)/$(ExtractRepoNames.CleanDriverWebsiteRepoName)/${{ parameters.applicationName }}.sln"
zipAfterPublish: false
modifyOutputPath: false
workingDirectory: "$(Build.SourcesDirectory)/$(ExtractRepoNames.CleanDriverWebsiteRepoName)/"
platform: ${{ parameters.buildPlatform }}
arguments: "--no-restore --configuration ${{ parameters.buildConfiguration }} --output $(Build.ArtifactStagingDirectory)"
script: |
echo "Building application..."
echo "Application Name: ${{ parameters.applicationName }}"
echo "Build Configuration: ${{ parameters.buildConfiguration }}"
echo "Build Platform: ${{ parameters.buildPlatform }}"
echo "Output Directory: $(Build.ArtifactStagingDirectory)"
# =============================================================================================
# CODE ANALYSIS
# =============================================================================================
# Run the SonarQube analysis on the built code (only on scheduled builds)
- task: SonarQubeAnalyze@7
displayName: "Run Code Analysis With SonarQube"
condition: eq('${{ parameters.runAnalysis }}', true)
env:
SONAR_SCANNER_OPTS: "-Xmx4096m"
inputs:
jdkversion: 'JAVA_HOME_17_X64'
# Publish the analysis results to SonarQube and check the quality gate (only on scheduled builds)
- task: SonarQubePublish@7
displayName: "Publish Quality Gate Result To SonarQube"
condition: eq('${{ parameters.runAnalysis }}', true)
inputs:
pollingTimeoutSec: '300'
Now, here is the very strange thingā¦
Out of sheer frustration, exhaustion and banging my head on my desk multiple times, I asked GitHub Copilot if it could do it for me. Mistakenly, it used the SonarQubePrepare@5 with MSBuild as the scannerMode, and also the SonarQubeAnalyze@5 and SonarQubePublish@5 ADO extensions instead of the SonarQubexxx@7 ones.
I ran this just for the sheer hell of it, and got the obvious deprecated warnings.
However, it ran perfectly, and more interestingly in around 4 minutes instead of the huge amount of time it had been taking previously. Below is the Azure DevOps YAML Pipeline code for this successful run.
# =============================================================================================
# SONARQUBE ANALYSIS (PREPARE)
# =============================================================================================
- task: SonarQubePrepare@5
displayName: 'Prepare SonarQube Analysis'
condition: and(succeeded(), eq('${{ parameters.runAnalysis }}', true))
inputs:
SonarQube: 'SonarQube'
scannerMode: 'MSBuild'
projectKey: 'cbs-ops_DriverWebsite_815157f7-b691-4e43-8a8c-fc7edd5339b7'
organization: 'Car Benefit Solutions Limited'
extraProperties: |
sonar.verbose=true
sonar.projectVersion=$(assemblyVersionNumber)
sonar.scm.provider=git
sonar.exclusions=**/bin/**/*,**/obj/**/*
sonar.branch.name=$(DriverWebsiteBranchName)
sonar.sourceEncoding=UTF-8
# =============================================================================================
# APPLICATION COMPILATION (WITH SONARQUBE ANALYSIS)
# =============================================================================================
# Build and publish the application using the .NET CLI
- task: DotNetCoreCLI@2
displayName: "Build ${{ parameters.applicationName }}"
env:
PostSharpLicense: $(postSharpLicenseKey)
inputs:
command: "build"
publishWebProjects: false
projects: "$(Build.SourcesDirectory)/$(ExtractRepoNames.CleanDriverWebsiteRepoName)/${{ parameters.applicationName }}.sln"
zipAfterPublish: false
modifyOutputPath: false
workingDirectory: "$(Build.SourcesDirectory)/$(ExtractRepoNames.CleanDriverWebsiteRepoName)/"
platform: ${{ parameters.buildPlatform }}
arguments: "--no-restore --configuration ${{ parameters.buildConfiguration }} --output $(Build.ArtifactStagingDirectory)"
script: |
echo "Building application..."
echo "Application Name: ${{ parameters.applicationName }}"
echo "Build Configuration: ${{ parameters.buildConfiguration }}"
echo "Build Platform: ${{ parameters.buildPlatform }}"
echo "Output Directory: $(Build.ArtifactStagingDirectory)"
# =============================================================================================
# SONARQUBE ANALYSIS (RUN)
# =============================================================================================
- task: SonarQubeAnalyze@5
displayName: 'Run SonarQube Analysis'
condition: and(succeeded(), eq('${{ parameters.runAnalysis }}', true))
# =============================================================================================
# SONARQUBE ANALYSIS (PUBLISH)
# =============================================================================================
- task: SonarQubePublish@5
displayName: 'Publish SonarQube Quality Gate Result'
condition: and(always(), eq('${{ parameters.runAnalysis }}', true))
inputs:
pollingTimeoutSec: '300'
Anyway, I obviously cannot continue down this route, but I just thought it was really interesting and might help highlight the issues I am having.
I just want to get this working now after many weeks trying to get things up and running, as it is extremely frustrating having spent thousands of pounds on a tool that we are unable to use.
Any guidance to save my sanity and sore head would be greatly appreciated.
I 100% get it is something I will be doing wrong, but I am giving up for now until I can get the necessary help as it just feels that anything else I do will be a waste of my very precious time.
Many thanks in advance
Logs-20250603.zip (1.6 MB)