-
ALM used: Azure DevOps
-
CI system used: Azure DevOps
-
Languages of the repository: C#
According to documentation:
It states as steps:
First define the prepare task:
- task: SonarCloudPrepare@3
inputs:
SonarCloud: 'YourSonarCloudServerEndpoint'
scannerMode: 'dotnet'
msBuildVersion: '<YourSonarScannerFullVersionNumber>'
projectKey: '<YourProjectKey>'
and then:
- task: Cache@2
displayName: Cache SonarScanner
inputs:
key: '"SonarScanner" | ".NET" | "$(Agent.OS)"'
path: '$(Agent.ToolsDirectory)/SonarScanner .NET'
but this does not really make much sense.
The cache should usually be resolved prior to the task that could potentially use the cache.
Moreover, the SonarCloudPrepare@3 requires dotnetScannerVersion in dotnetmode (not msBuildVersion - documentation seems to be wrong here)
and since that value can change i would assume it must be part of the cache key - correct?
Example:
- task: Cache@2
displayName: Cache SonarScanner
inputs:
key: '"SonarScanner" | ".NET" | "$(Agent.OS)" | "${{ parameters.SonarCloudMsBuildVersion}}"'
path: '$(Agent.ToolsDirectory)/SonarScanner .NET'
Can you please elaborate on how the correct order of tasks should be and how the internals of the SonarCloudPrepare@3 works on using a cache that being hit after the task has run?
For brevity this is how I have currently setup my pipeline as it follows the general way of doing cache.
- Restore Cache if applicable.
- The extension is either internally aware if a cache has been restored or you inform via setting cache variable
- The cache task automatically cache any non hits at the end of the pipeline
- task: Cache@2
displayName: Cache SonarScanner
inputs:
key: '"SonarScanner" | ".NET" | "$(Agent.OS)" | "${{ parameters.SonarCloudMsBuildVersion}}"'
path: '$(Agent.ToolsDirectory)/SonarScanner .NET'
- task: SonarCloudPrepare@3
displayName: Sonarcloud Setup for analysis of the codebase
inputs:
SonarCloud: 'SonarCloud'
organization: ${{ parameters.SonarCloudOrganisation }}
scannerMode: 'dotnet'
dotnetScannerVersion: ${{ parameters.SonarCloudMsBuildVersion}}
projectKey: $(SonarCloudGeneratedProjectKey)
projectName: $(SonarCloudGeneratedProjectName)
extraProperties: |
sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/coverage.opencover.xml
sonar.scanner.metadataFilePath=$(Agent.TempDirectory)/sonar/$(Build.BuildNumber)/report-task.txt
$(SonarCloudDebugSettings)
Thanks.