How to fail an Azure pipline on a failed Sonar quality gate

We are using

  • Developer Edition
  • Version 8.3.1 (build 34397)

We are moving our pipelines from Jenkins to Azure, Currently in Jenkins our pipelines correctly fail if the SonarQuality gate is not passed.
We are having problems replicate this in Azure
Our yaml looks like

- task: SonarQubePrepare@4
    inputs:
      SonarQube: 'Devlopment-Sonarqube'
      scannerMode: 'CLI'
      configMode: 'manual'
      cliProjectKey: ${{ parameters.sonarProjectKey }}
      cliProjectName: ${{ parameters.sonarProjectName }}
      cliSources: 'app'
  - task: SonarQubeAnalyze@4
  - task: SonarQubePublish@4
    inputs:
      pollingTimeoutSec: '300'

This works in the sense that we can see the see the code has been scanned and correctly failed in Sonar itself. But we want the pipeline to end at this point if it fails

I’ve seen others have had this problem, and have resulted in calling the rest API. Is this still the best method? E.g Something like

Hi @jerry.brimacombe,

Welcome to SonarSource community! :wave:

Are you able to still block merges if the quality gate fails? Perhaps these community guides will help:

Joe

Thank you for your replies - we will look to do this. It certainly seems like something we should do,
However, we really also just want the pipeline to fail. At the moment we have achieved this by calling the rest API - which works, but just seems on overly complex way of achieving something that would appear to be a standard requirement.

There are azure devops extensions in the marketplace that can achieve what you want.