Enforcing Quality Gate via Maven

Hello,

Our goal is to enforce the quality gate on each pipeline build. However, I am not quite sure how to achieve this.

Summary:

  • SonarCloud
  • Enforce quality gate via Maven
  • Tried to locate some formal documentation on how to achieve this.

The goal is to enforce the quality gate via the bitbucket pipeline. The line invoking the SonarCloud maven plugin:

            mvn -B -Dmaven.wagon.http.pool=false org.jacoco:jacoco-maven-plugin:prepare-agent
            test org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

Here is the entire pipeline section

    - step: &unit_tests
        name: Run unit tests and SonarCloud scan
        caches:
          - maven
          - sonar
          - yum
        script:
          - yum -y install dejavu-fonts-common
          - >
            mvn -B -Dmaven.wagon.http.pool=false org.jacoco:jacoco-maven-plugin:prepare-agent
            test org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

The question is this. Given the above pipeline, how do we enforce the pipeline to fail when the quality gate fails?

Thank you for your help.
/.

The simplest way is if the SonarQube server has the “BuildBreaker” plugin configured, and you enable it in the scan. If a quality gate fails, the Maven goal will fail.

Hello David,

Thank you for your answer. I am having difficulty finding BuildBreaker in SonarCloud. Where is this plugin located. Is there a way to install it or configure it?

/.

Sorry, I don’t know what the capabilities are of SonarCloud.

Thank you David. By the looks of it, what I’m looking for is not possible: https://jira.sonarsource.com/browse/MMF-1849
/.

Hey there.

Setting -Dsonar.qualitygate.wait=true is an option available to you, after reading this blog post :smiley:

It’s not perfect but should help out until MMF-1849 gets implemented (if it ever does)