How to get dotnet-sonarscanner to fail if the quality gate fails

Using SQ 8.5.

Running a script (in Gitlab CI) to analyses a dotnet core project:

dotnet test -p:CollectCoverage=true -p:CoverletOutputFormat=opencover -p:CoverletOutput=/project/coverage.xml
dotnet build-server shutdown
dotnet-sonarscanner begin -k:$SONAR_PROJECT_KEY -d:sonar.login=$SONAR_TOKEN -d:sonar.cs.opencover.reportsPaths=/project/coverage.xml
dotnet build
dotnet-sonarscanner end -d:sonar.login=$SONAR_TOKEN

But i need the script to fail if the quality gate fails - any idea how to do this?

Hi Gilbert, welcome to the Community!

Please have a look at this guide on How to block the merge of Merge Requests when SonarQube Quality Gate is failed, with GitLab.

I am sure you will find there how to achieve what you are looking for. In any case I would suggest for you to work with failing Pull Request pipelines instead of failing the branch pipelines, as this may impede your developers from testing their code.

Best regards,

Thanks Daniel, it’s working now.

I added this option: -d:sonar.qualitygate.wait=true

on begin scan

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.