Is there a way to run a sonarscan and publish the results to the quality gate AzureDevops policy from a docker container running in an AzureDevops yml pipeline. We have the sonarscannercli begin and end tasks, but no equivalent to the “SonarCloudPublish” task that is available within a docker container.
We’ve tried a few workarounds. Like copying out the .sonarqube folder from the docker image, then using the publish task from the .yml file, but the paths don’t match. I’ve check the community topics for any solution, the closest I’ve found is these two topics:
In both of them, a solution using webhooks is suggested, but the linked docs is far away from being useful for this.
I’ve a lot of questions regarding this:
What is the URL, I configure the webhook to post?
How do I configure the authentication?
What does the request look like, the quality gate endpoint accepts to approve the pull request?
Is it the same as the webhook publishes, or do I need a service that transforms the request?
The sonarcloud webhook calls azure devops to tell it the quality gate is approved? Is this what we are supposed to do? I’m just guessing, because the documentation about this is pretty much non existent.
It is very common to have a build run in a docker container, yet we don’t have a sonarcli task, or any useful documentation about how to do this.
To be clear, SonarQubeAnalyze submits the report to SonarCloud – SonarCloudPublish tags the build with the Quality Gate, but this is purely visual, it does not block the merge of your Pull Request or interact with the build policy whatsoever. It is not particularly useful.
Do you currently have orchestrated analyses of your pull requests configured within the context of your Docker build?
That means the correct values are being passed to the sonar.pullrequest.*analysis parameters in the context of a pull request build (sonar.pullrequest.key, sonar.pullrequest.base, and sonar.pullrequest.branch).
This values are automatically configured when using the Azure DevOps Extension. You can get an idea of how they’re derived here.
After that, as long as you have a bound organization and project, you should be able to receieve Pull Request Analysis in SonarCloud, and Pull Request Decoration which allows you to add a status policy
The quality gate check stays stuck in waiting unless we use the publish task. We’ve configured the sonarscanner begin task the following way (only the relevant configs are shown here):
When using the SonarQubePublish task, it means the Azure pipelines job won’t be complete until the Quality Gate is computed SonarCloud-side. It does not affect the actual status.
Is it possible that when running the build without SonarQubePublish, the status appears populated after you are able to view the PR in SonarCloud?
My understanding is that when the project is bound there should be data that’s always available to SonarCloud when decorating PRs. That data doesn’t seem to be there on the PR you shared with me.
This is data that is set also by the Extension for Azure DevOps (but only meant to be used when a project isn’t bound). That’s these analysis parameters and corresponding build variables:
Can you give it a go configuring these in your Docker build to see if it results in the PR being decorated? On my side, I’ll flag this for attention as the logs look really odd.
Thanks. I will still flag this for attention as this shouldn’t be required (even if we wish all users were just using our Azure DevOps tasks that populate these values )