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
            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:

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

        - task: VisualStudioTestPlatformInstaller@1
          displayName: 'Install VSTest'
            packageFeedSelector: 'nugetOrg'
            versionSelector: 'latestPreRelease'
        - task: VSTest@2
          displayName: 'Run VSTest'
            testSelector: 'testAssemblies'
            testAssemblyVer2: |
            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'
            ProjectDirectory: '$(Build.SourcesDirectory)'            

        - task: SonarQubeAnalyze@4
        - task: SonarQubePublish@4
            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: )


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