Make 'Quality Gate' a required check in an Azure DevOps PR

I have an Azure DevOps Git repo configured with a protected main branch. The protection is set to run an Azure DevOps pipeline that calls SonarQube, the core bit of YAML is below

        - task: SonarQubePrepare@4
          inputs:
            SonarQube: 'SonarQube'
            scannerMode: 'MSBuild'
            projectKey: '$(SonarQubeProjectKey)'
            projectName: '$(SonarQubeName)'
            projectVersion: '$(GitVersion.Major).$(GitVersion.Minor)'
            extraProperties: |
              # Additional properties that will be passed to the scanner, 
              # Put one key=value per line, example:
              sonar.dependencyCheck.reportPath=$(Build.SourcesDirectory)/dependency-check-report.xml
              sonar.dependencyCheck.htmlReportPath=$(Build.SourcesDirectory)/dependency-check-report.html
              sonar.cpd.exclusions=**/AssemblyInfo.cs,**/*.g.cs
              sonar.cs.vscoveragexml.reportsPaths=$(System.DefaultWorkingDirectory)/**/*.coveragexml
              sonar.cs.vstest.reportsPaths=$(System.DefaultWorkingDirectory)/**/*.trx

        - task: DotNetCoreCLI@2
          displayName: 'Build the dotnet projects'
          inputs:
            command: 'build'
            projects: '$(Build.SourcesDirectory)/src/**/*.csproj'

        - task: VisualStudioTestPlatformInstaller@1
          displayName: 'Install VSTest'
          inputs:
            packageFeedSelector: 'nugetOrg'
            versionSelector: 'latestPreRelease'
            
        - task: VSTest@2
          displayName: 'Run VSTest'
          inputs:
            testSelector: 'testAssemblies'
            testAssemblyVer2: |
              **\*UnitTests.dll
              !**\*TestAdapter.dll
              !**\obj\**
            searchFolder: '$(Build.SourcesDirectory)/src'
            resultsFolder: '$(System.DefaultWorkingDirectory)\TestResults'
            runInParallel: true
            codeCoverageEnabled: true
            rerunFailedTests: true
            runTestsInIsolation: true
            runOnlyImpactedTests: false
  
        - task: CodeCoverage-Format-Convertor@1
          displayName: 'Convert code coverage file to XML format'
          inputs:
            ProjectDirectory: '$(Build.SourcesDirectory)'            

        - task: SonarQubeAnalyze@4
        - task: SonarQubePublish@4
          inputs:
            pollingTimeoutSec: '300'

When I create a PR, the pipeline is running and SonarQube finds issues, as expected.

SonarQube decoration is setup and is working, I can see the SonarQube issues in PR comments.

My question is about the PR showing an optional check that the SonarQube ‘Quality Check’ failed.

Can I make it so that the ‘Quality Check’ is a required PR check?

If it is in the documentation I cannot find it.

Hey @rfennell ,
Maybe you are referring to the Status Check option in Azure DevOps?


(example here with SonarCloud Quality Gate, but the principle is the same with SonarQube)

1 Like

That is exactly what I was looking for, just could not see it in the documentation. I had not realised on the ‘Status Checks’ the options ones were listed in the drop down.

Thanks again

Happy to help :slight_smile:
Btw, feel free to leave a rating on the marketplace if our extension fits your needs :slight_smile: (or come back to me if something bothers you :wink: )

Christophe

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