Code Coverage showing 0% on sonar cloud for swift project

Please help
Below is My Azure Yml file setup for bitbucket repo. Pull request is failing as 80% code coverage is setup as measures on sonar cloud. Sonar cloud is showing 0% as attached screenshot. Can anyone help here to show code coverage on sonar cloud. I hade tried with .xml, .xcresult, .sh file but nothing worked. Pipeline gets succeed without failing.
echo “Running Sonar Scanner…”
sonar-scanner
-Dsonar.organization=“framework”
-Dsonar.projectKey=“framework”
-Dsonar.projectName=“framework”
-Dsonar.scannerMode=“CLI”
-Dsonar.SonarCloud=“sonarcloud-framework”
-Dsonar.host.url=“https://sonarcloud.io
-Dsonar.token=$(SONARTOKEN)
-Dsonar.swift.coverage.reportPaths=“$XML_FILE”
#-Dsonar.coverageReportPaths=“$XML_FILE” \


echo “Running Sonar Scanner…”
sonar-scanner
-Dsonar.organization=“framework”
-Dsonar.projectKey=“framework”
-Dsonar.projectName=“framework”
-Dsonar.scannerMode=“CLI”
-Dsonar.SonarCloud=“framework”
-Dsonar.host.url=“https://sonarcloud.io
-Dsonar.token=$(SONARTOKEN)
-Dsonar.swift.coverage.reportPaths=“$XML_FILE”
#-Dsonar.coverageReportPaths=“$XML_FILE” \

trigger:

  • Sprint/Sprint24.24/PublishSonarCodeCoverage

pool:
vmImage: ‘macOS-latest’

jobs:

  • job: BuildJob
    displayName: Build, Test, Analyze, and Deploy to SonarCloud

    variables:

    SONAR_SCANNER_VERSION: ‘4.4.0.2170’

    #SONAR_SCANNER_HOME: $(Agent.HomeDirectory)/.sonar/sonar-scanner-$(SONAR_SCANNER_VERSION)-linux
    BUILD_WRAPPER_DOWNLOAD_URL: https://sonarcloud.io/static/cpp/build-wrapper-macosx-x86.zip
    sonar_cfamily_build_wrapper_output: path/to/build-wrapper-output

    steps:

    • task: InstallAppleCertificate@2
      displayName: Installing Developer Apple Certificates
      inputs:
      certSecureFile: ‘KPCertificates_1234.p12’
      keychain: ‘temp’
      certPwd: ‘1234’ # Consider using secrets management
      deleteCert: true

    • task: InstallAppleProvisioningProfile@1
      displayName: Installing SDK Provisioning Profile
      inputs:
      provisioningProfileLocation: ‘secureFiles’
      provProfileSecureFile: ‘DevelopmentKastlePresence.mobileprovision’
      removeProfile: true

    • task: SonarCloudPrepare@3
      displayName: SetupSonarConnection
      inputs:
      SonarCloud: “sonarcloud-HID-Integration-iOS-new”
      organization: “framework”
      scannerMode: “CLI”
      projectKey: “SampleiOS”
      projectName: ‘SampleIOS’
      extraProperties: |
      sonar.branch.name=Sprint/Sprint24.24/PublishSonarCodeCoverage

    - script: |

    echo “Setting up SonarScanner”

    mkdir -p $(SONAR_SCANNER_HOME)

    curl --create-dirs -sSLo $(SONAR_SCANNER_HOME)/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$(SONAR_SCANNER_VERSION)-linux.zip

    unzip -o $(SONAR_SCANNER_HOME)/sonar-scanner.zip -d $(SONAR_SCANNER_HOME)

    export PATH=$(SONAR_SCANNER_HOME)/bin:$PATH

    displayName: “Download and Setup SonarScanner”

    • bash: |
      mkdir -p $HOME/.sonar
      curl -sSLo $HOME/.sonar/build-wrapper-macosx-x86.zip ${{variables.BUILD_WRAPPER_DOWNLOAD_URL}}
      unzip -o $HOME/.sonar/build-wrapper-macosx-x86.zip -d $HOME/.sonar/
      displayName: Download and install build wrapper

    • bash: |
      mkdir build
      cmake -S . -B build
      export PATH=$HOME/.sonar/build-wrapper-macosx-x86:$PATH
      build-wrapper-macosx-x86 --out-dir build_wrapper_output_directory cmake --build build/ --config Debug
      workingDirectory: .
      displayName: Build in build-wrapper

    • script: |
      echo “Preparing iOS environment”
      xcrun simctl list
      xcrun simctl boot “iPhone 15” || echo “Simulator already booted”
      xcodebuild clean build test
      -project framework/framework.xcodeproj
      -scheme framework
      -destination ‘platform=iOS Simulator,name=iPhone 15’
      -configuration Debug
      -sdk iphonesimulator
      -enableCodeCoverage YES
      -derivedDataPath /tmp/derivedData/
      displayName: “Build and Run Tests”

    Step 4: Generate Coverage Report in SonarQube Generic Format

    • script: |
      echo “Generating SonarQube-compatible coverage report…”

      Directory containing the .xcresult files

      LOGS_DIR=“/tmp/derivedData/Logs/Test”
      # Use find to locate the .xcresult file
      COVERAGE_RESULT_PATH=$(find “$LOGS_DIR” -name “*.xcresult” -print -quit)

      Define output path for coverage report

      COVERAGE_OUTPUT_PATH=“/tmp/derivedData/Logs/Test/CoverageNew.xml”

      Ensure output directory exists

      OUTPUT_DIR=$(dirname “$COVERAGE_OUTPUT_PATH”)
      mkdir -p “$OUTPUT_DIR”

      echo “xml file created /tmp/derivedData/Logs/Test/”
      ls -l /tmp/derivedData/Logs/Test/

      Download the Sonar-provided script for conversion

      echo “Downloading the Sonar-provided conversion script…”
      curl -LO https://raw.githubusercontent.com/SonarSource/sonar-scanning-examples/master/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh

      echo “Moving .sh file to Test directory”
      mv xccov-to-sonarqube-generic.sh /tmp/derivedData/Logs/Test/

      COVERAGE_shFile = “/tmp/derivedData/Logs/Test/xccov-to-sonarqube-generic.sh”
      echo “66 Found .xcresult file COVERAGE_shFile: $COVERAGE_shFile”
      echo “77 Size of $COVERAGE_shFile: $(stat -f%z “$COVERAGE_shFile”) bytes”

      Make the script executable

      chmod +x /tmp/derivedData/Logs/Test/xccov-to-sonarqube-generic.sh

      Run the conversion script to generate the coverage report

      echo “Running the conversion script to generate SonarQube-compatible coverage report…”
      bash /tmp/derivedData/Logs/Test/xccov-to-sonarqube-generic.sh “$COVERAGE_RESULT_PATH” > “$COVERAGE_OUTPUT_PATH”
      displayName: “Generate Coverage Report”

    • script: |
      echo “Running Sonar Scanner…”
      XML_FILE=$(find /tmp/derivedData/Logs/Test -name “.xml" -print -quit)
      SH_FILE=$(find /tmp/derivedData/Logs/Test -name "
      .sh” -print -quit)
      XC_FILE=$(find /tmp/derivedData/Logs/Test -name “*.xcresult” -print -quit)

      echo “66 Found .XML_FILE file XML_FILE: $XML_FILE”
      echo “77 Size of $XML_FILE: $(stat -f%z “$XML_FILE”) bytes”
      echo “88 Found .SH_FILE file XML_FILE: $SH_FILE”
      echo “99 Size of $SH_FILE: $(stat -f%z “$SH_FILE”) bytes”
      echo “111 Found .xcresult file XC_FILE: $XC_FILE”
      echo “222 Size of $XC_FILE: $(stat -f%z “$XC_FILE”) bytes”

      echo “xml file created /tmp/derivedData/Logs/Test/”
      ls -l /tmp/derivedData/Logs/Test/

      echo “Downloading and setting up Sonar Scanner…”
      brew install sonar-scanner
      sonar-scanner --version

      echo “Running Sonar Scanner…”
      sonar-scanner
      -Dsonar.organization=“framework”
      -Dsonar.projectKey=“framework-integration-ios”
      -Dsonar.projectName=“framework-iOS”
      -Dsonar.scannerMode=“CLI”
      -Dsonar.SonarCloud=“framework”
      -Dsonar.host.url=“https://sonarcloud.io
      -Dsonar.token=$(SONARTOKEN)
      -Dsonar.swift.coverage.reportPaths=“$XML_FILE”
      #-Dsonar.coverageReportPaths=“$XML_FILE”
      displayName: “Run Sonar Scanner”

    • task: SonarCloudAnalyze@3
      displayName: Sonar Report Analysis

    Publish Quality Gate results

    • task: SonarCloudPublish@3
      displayName: Sonar Report Publish
      inputs:
      pollingTimeoutSec: ‘300’

What do the logs say about importing code coverage?

https://community.sonarsource.com/t/how-to-find-logs-about-importing-code-coverage/73317/3

Pleae also note that if you’re using xccov-to-sonarqube-generic.sh, you need to pass the report to sonar.coverageReportPaths, SonarQube Cloud’s Generic Coverage format.