How to fail a Bitbucket pipeline when Sonar quality tests fail?

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve
  • what have you tried so far to achieve this

We’re using sonarqube v2.7.1 and scanner plugin 4.0.0.

When we create a Bitbucket pull request (PR), we want to be able to fail the PR when it doesn’t meet Sonar code quality gate. I read SonarQube Pull Requests in Bitbucket Cloud and able to make it work, that is, the sonar scanner runs when we create a PR. Here’s the Bitbucket pipeline.

pipelines:
  pull-requests:
    "**":
    - step:
        name: SonarQube Analysis
        image: newtmitch/sonar-scanner:4.0.0-alpine
        size: 2x
        script: # Modify the commands below to build your repository.
          # You must commit the Gradle wrapper to your repository
          # https://docs.gradle.org/current/userguide/gradle_wrapper.html
          - ./gradlew clean build
          - sonar-scanner -Dsonar.projectBaseDir=$(pwd)
            -Dproject.settings=sonar.properties
            -Dsonar.bitbucket.oauthClientKey=$SONAR_OAUTH_CLIENT_KEY
            -Dsonar.bitbucket.oauthClientSecret=$SONAR_OAUTH_CLIENT_SECRET
            -Dsonar.login=$SONAR_LOGIN

However, even though we fail the quality threshold, the pipeline still passes. How can we fail the pipeline for Sonar quality gate failure?

Hello,

  • You’re obviously using a 3rd party plugin to integrate SonarQube with BitBucket Cloud Pull Requests.
  • You’re using a custom Docker image to run the scanner
  • You state that you use SonarQube 2.7.1, I can’t believe this is true. This release, if it even existed, would be 8 or 10 years old. Latest is 8.3.1

Based on the above there’s nothing we can help you on with your problem.

Fyi, SonarQube will provide in the coming months exactly the feature you want in Developer Edition and above. See https://jira.sonarsource.com/browse/MMF-1944

Olivier

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

@ChrisZift Hi, just to let you know that the latest flavor of SonarQube, the 8.7, solve your problem. It is supposed to be released within the next few days :slight_smile:

Hope to help.
Regards,
Christophe