Bitbucket Sonarcloud quality gate in builds

Hi,

we are using Sonarcloud to test code for Android (Kotlin; gradle) and iOS(Swift). Pull Requests in both repos are decorated with the quality gate which is good!

However, we only have the result in the build table of bitbucket in the Android Repo.
image

I however can’t find a way to enable/disable this feature to have the result in the builds. Currently, we don’t want to have a blocking quality gate, so we want to remove it from the builds section. In the future however, I could see our teams enforcing more quality and this should be blocking so we want to enable this feature.

Also only in the Android Repo there are comments directly in the code which would be nice to have for iOS aswell
image

For our pipelines, we are using Azure Devops. These are the configs:
iOS:

pr:
  autoCancel: true  # cancel running PR builds when a new commit lands in the branch.


pool:
  vmImage: macOS-12

variables:
  - group: fastlane
  - name: IS_CI
    value: 1

steps:
  - checkout: self
    persistCredentials: true

  - task: UseRubyVersion@0
    inputs:
      versionSpec: "~ 2.7"
      addToPath: true
    displayName: Use Ruby 2.7

  - script: gem install bundler:2.3.17
    displayName: Install desired bundler version

  - script: |
      bundle --version
      ruby --version
    displayName: Print bundler and ruby versions

  - script: bundle install
    displayName: Install Gems

  - task: SonarCloudPrepare@1
    inputs:
      SonarCloud: 'Sonarcloud'
      organization: 'org-repository'
      scannerMode: 'CLI'
      configMode: 'manual'
      cliProjectKey: 'Org-app-ios'
      cliProjectName: 'org-app-ios'
      cliSources: '.'
      extraProperties: |
        # Additional properties that will be passed to the scanner, 
        # Put one key=value per line, example:
        # sonar.exclusions=**/*.bin
        sonar.coverageReportPaths=./fastlane/test_output/sonarqube-generic-coverage.xml

  - script: bundle exec fastlane ios test_app
    displayName: Run app tests

  - script: bundle exec fastlane ios code_cov
    displayName: Run code coverage

  - task: SonarCloudAnalyze@1

  - task: SonarCloudPublish@1
    inputs:
      pollingTimeoutSec: '300'

  - task: PublishBuildArtifacts@1
    inputs:
      pathToPublish: fastlane/test_output
      artifactName: test-results

Android:

trigger:
- develop  # note This Pipeline is also triggered through webhooks on Pull Requests

pool:
  vmImage: 'ubuntu-latest'

steps:
  - task: SonarCloudPrepare@1
    inputs:
      SonarCloud: 'Sonarcloud'
      organization: 'org-repository'
      scannerMode: 'CLI'
      configMode: 'manual'
      cliProjectKey: 'Org-app-android'
      cliProjectName: 'org-app-android'
      cliSources: '.'
      extraProperties: |
        # Additional properties that will be passed to the scanner,
        # Put one key=value per line, example:
        # sonar.exclusions=**/*.bin
        sonar.coverage.jacoco.xmlReportPaths=**/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml

  - task: Gradle@1
    inputs:
      gradleWrapperFile: 'gradlew'
      gradleOptions: '-Xmx3072m'
      publishJUnitResults: true
      failTaskOnFailedTests: true
      testResultsFiles: '**/TEST-*.xml'
      tasks: 'jacocoTestReport'

  - task: SonarCloudAnalyze@1

  - task: PublishCodeCoverageResults@1
    inputs:
      codeCoverageTool: 'JaCoCo'
      summaryFileLocation: "$(System.DefaultWorkingDirectory)/**/reports/jacoco/jacocoTestReport/jacocoTestReport.xml"
      reportDirectory: "$(System.DefaultWorkingDirectory)/**/reports/jacoco/jacocoTestReport/html"

  - task: SonarCloudPublish@1
    inputs:
      pollingTimeoutSec: '300'

Hi,

Am I right in thinking this is about displaying

  • Quality Gate status
  • for branches, not PRs
  • in your CI, not the repo

?

If so, I fear I have to disappoint you…

 
Ann

Hi Ann,

its about displaying the build status in a PR itself. I’m not sure why the build in the red circle is present for Android but not for iOS Pull Requests (different Repo same settings as far as I can see)

Is there a way to disable this? All Builds must be green before merging is allowed. But we currently don’t want Sonarcloud to be blocking (failed quality gate means failed build task)

ping @ganncamp
Any update?

Any update?

We would like to have the Sonarcloud result as a build for iOS too (see Screenshot of my last post). This would allow us to block merges if quality gates are not met. I can’t see where I could enable this however :frowning:

Hi,

It seems you have two questions:

Why the build in the red circle (SC Quality Gate) is present for Android but not for iOS Pull Requests?

I think there is a problem with the trigger setting between the Azure Pipeline and the Bitbucket repository.
On the webhooks page in Bitbucket repository settings, there should be repository hooks definitions.
You can define them under the ‘Triggers’ tab in your Azure pipeline definition.
See the instructions in this document for how to do.

All Builds must be green before merging is allowed. But we currently don’t want Sonarcloud to be blocking (failed quality gate means failed build task). Is there a way to disable this?

Yes, there is a way to do this. You could define a new, simpler Quality Gate on SonarCloud to not block your merge process (for example, 0% test coverage required to pass) and configure your Azure Pipeline to use this new Quality Gate for this repository.

I hope this helps.

Thank you, someone disabled the web hooks on Azure Devops. This fixed the problem for me!

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