SonarQubePublish when built and analysed in docker

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

  • what are you trying to achieve
    Building our .NET app in docker & azure-pipelines, we would like to publish quality report in the build. However i’m not sure how I should do this, I don’t think SonarQubePublish will help here

Example dockerfile:


RUN dotnet sonarscanner begin \
	/o:"$SONAR_ORG" \
	/k:"$SONAR_PRJ_KEY" \
    /v:"$BUILD_VERSION" \
    /"$SONAR_HOST" \
	/d:sonar.login="$SONAR_TOKEN" \
	/d:sonar.coverageReportPaths="/testresults/SonarQube.xml" \

RUN dotnet build MyApp.sln -c Release --no-restore

RUN dotnet test MyApp.sln --logger "trx" --collect:"XPlat Code Coverage" -r /testresults --no-build -c Release

## Create the code coverage file in sonarqube format using the cobertura file generated from the dotnet test command
RUN reportgenerator "-reports:/testresults/*/coverage.cobertura.xml" "-targetdir:/testresults" "-reporttypes:SonarQube;HtmlInline_AzurePipelines;Cobertura"

RUN dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"


Example azure-pipelines.yaml


# a custom template that runs "docker build ...' and copies the content of '/testresults' to $(System.DefaultWorkingDirectory)/TestResults

- template: steps/docker/dotnet/testV2.yml@templates
    arguments: "--build-arg SONAR_PRJ_KEY=$(SonarProject)  --build-arg SONAR_PRJ_KEY=$(SonarProject) --build-arg SONAR_TOKEN=$(SonarToken)"
- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage from TestResults/**/*.cobertura.xml'
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(System.DefaultWorkingDirectory)/TestResults/Cobertura.xml'
    reportDirectory: '$(System.DefaultWorkingDirectory)/TestResults'
    pathToSources: '$(System.DefaultWorkingDirectory)'


This builds and publishes the results correctly to sonarqube, however:

How can I now use the following task (or an alternative) to have the quality report reported in the build:

# Publish Quality Gate Result task
- task: SonarQubePublish@5
    pollingTimeoutSec: '300'

As a side note:

Building / testing the app outside of Docker is undesired for us, as those tests might have (linux) dependencies like ‘ghostscript’ or other to run properly.
Installing these on the build server is unwanted behaviour for us.

Hey there.

sonar-scanner-vsts is open source if you’d like to dig in and figure out how the build property is populated.

So in other words you can’t except if you hack something together as that task requires a bunch of files and variables to be set.