SonarQube with Bitbucket Pipeline for iOS App in Mac OS

 Integrating SonarQube or SonarCloud with an iOS project in a Bitbucket repository using pipelines involves several steps. Here’s a detailed guide:


1. Set up SonarQube/SonarCloud

  • SonarQube:
    • Install and configure a SonarQube server (if not using a hosted solution).
    • Create a new project in SonarQube.
    • Generate a project key and token for authentication.
  • SonarCloud:
    • Log in to SonarCloud using your Bitbucket account.
    • Create a new project, selecting the Bitbucket repository.
    • Generate a project key and token.

2. Configure the iOS Project

  1. Install Sonar Scanner:

    • Use Homebrew to install the scanner:
      bash
      brew install sonar-scanner
    • Verify the installation:
      bash
      sonar-scanner --version
  2. Generate SonarQube Configuration File (sonar-project.properties):

    • Place this file in the root directory of your iOS project.
    • Example configuration:
      properties
      sonar.projectKey=your_project_key sonar.organization=your_organization_key (if using SonarCloud) sonar.host.url=https://your-sonar-url (SonarQube) or https://sonarcloud.io sonar.login=your_token # Source settings sonar.sources=. sonar.language=swift sonar.swift.simulator=platform=iOS Simulator,name=iPhone 14,OS=16.4 sonar.exclusions=**/*.test.swift,**/Carthage/**,**/Pods/** # Coverage sonar.coverage.exclusions=**/*.test.swift sonar.swift.coverage.reportPaths=build/reports/coverage/coverage.json
  3. Set up Test Coverage:

    • Use xccov or tools like slather to generate test coverage reports in coverage.json.

3. Configure Bitbucket Pipelines

  1. Enable Pipelines:

    • Go to your Bitbucket repository.
    • Under Settings > Pipeline > Settings, enable Pipelines.
  2. Add a bitbucket-pipelines.yml File:

    • In the root directory of your repository, create or modify the pipeline configuration file:
      yaml
      image: appleboy/drone-sonar-runner pipelines: default: - step: name: Build and Analyze image: appleboy/drone-sonar-runner script: - xcodebuild clean build test -scheme YourScheme -destination 'platform=iOS Simulator,name=iPhone 14,OS=16.4' - sonar-scanner services: - docker
  3. Customize the Pipeline:

    • Adjust the xcodebuild and sonar-scanner commands according to your project.
    • Use caching to speed up builds:
      yaml
      definitions: caches: sonar: ~/.sonar/cache
  4. Secure Secrets:

    • Store sensitive details like SonarQube/SonarCloud tokens in Bitbucket Repository Variables (under Repository Settings > Repository Variables).

4. Run the Pipeline

  • Push the changes to your Bitbucket repository.
  • Trigger the pipeline manually or let it run automatically on the next push.
  • Check the SonarQube/SonarCloud dashboard for analysis results.


Getting this error "Could not find 'java' executable in JAVA_HOME or PATH."


Comments

Popular posts from this blog

Your build is currently configured to use incompatible Java 21.0.3 and Gradle 8.2.1. Cannot sync the project.

Google Assistant Implementation in Android application with app actions