SonarCloud Analysis for Pull Requests on Multi-Stage Pipeline Won't Complete after build stage

We are using SonarCloud Analysis in our Azure DevOps pipelines. We have recently converted a number of our pipelines from build / release to entirely YAML multi-stage pipeline.

We have set build validation to do sonarcloud analysis on our main branch, so we get analysis on pull requests. What we are seeing is that the sonarcloud analysis will continuously run until the entire pipeline completes, from build all the way to production for the multi-stage configuration. It doesn’t stop as expected as the build stage completes. In the build stage we have a prepare, complete analysis, and publish analysis step, but still does not work as expected. Has anyone else seen this or is there an additional task stop the analysis on the build step?

Hi @tashtechs and welcome to the community !

Could you please share a snippet of your whole pipeline just to see if everything looks ok on that side ?

Thanks in advance.

Sample YAML.txt (4.8 KB)

Hi @mickaelcaro , Here is my sample YAML for Build and Dev

Also thank you for the welcome and help!

Thanks for the snippet. I don’t see any obvious mistake here or possible error.

Is this a particular task from SonarCloud which is hanging ?

It is the SonarCloud analysis on the Pull Requests. From the pipeline / build step, it all looks fine. The analysis, publish finish, but because there is still active stages - dev, test, etc. it won’t complete on the pull request until all the stages are complete - not just Build.

I think this is more a limitation of the Yaml pipeline itself rather than us.

The status posted on the PR is made whenever we complete on our side the analysis (the background process that is done). But on Azure DevOps, i think they’ll wait until the whole build is done to update things.

Can you just try to desactivate your post-build actions (let the SonarCloud analysis, but without any deployment) just temporarly to verify this assumption ?


Yes, the analysis will finish on the PR if there is only the build stage completed and no further stages, but we want those additional stages. It is very valuable to have our entire pipeline in source code for future projects. Is there a way to hard kill that process for the analysis after the build step? Maybe a powershell task or something? Right now, we have that build validation step as optional so we can process our PRs as a workaround. We would like to see the analysis on the PR for successful builds of feature branches prior to merging to main/master. Unfortunately this is broken with the full YAML pipeline.

Can you just have maybe a separate build for PR only that does SonarCloud analysis and build ?

I tried to check how job deal with that on the MS doc, but haven’t found anything interesting so far, or maybe add an approval to the deployment so that the build terminates (or hangs) and you have the approve the deployment job, but not sure that it will solve your problem.


The approval and branch check policy do not work unfortunately. I did setup a second pipeline yesterday that just does build and analysis which does work after updating the Build Validation policy to point to the new pipeline. I can go with the workaround. Just a shame, now I have to double my pipelines for this functionality.

1 Like

Maybe you can ask the dev community here :

Either they’ll have a better suitable solution for you, or report a kind of bug ?