SonarQube Developer Edition Swift Code Coverage

Hi,

Pproduct: SonarQube developer edition
XCode Version: 13.0
Platform: iOS
Language: Swift
VCS: Azure

What am I trying to achieve

I used SonarQube Developer Edition. I want to push coverage report to sonarqube with azure pipeline. But I don’t know how to do. Please help.

I read [Coverage & Test Data] Generate Reports for Swift this document but how to add coverage task to azure pipeline with swift language

This is yml file.

variables:
- group: MobileAppsVariableGroup

trigger:
- qa

pool:
  vmImage: 'macos-11'
  demands: xcode

steps:
- task: CocoaPods@0
  displayName: 'iOS CocoaPods installation'

- task: InstallAppleCertificate@2
  displayName: 'iOS Apple certificate installation'
  inputs:
    certSecureFile: 'blablabla '
    certPwd: 'blablabla
    keychain: 'temp'

- task: InstallAppleProvisioningProfile@1
  displayName: 'iOS Apple provisioning profile installation'
  inputs:
    provisioningProfileLocation: 'secureFiles'
    provProfileSecureFile: 'FordTruckProd.mobileprovision'

**- task: SonarQubePrepare@5**
**  inputs:**
**    SonarQube: 'SonarQubeDev'**
**    scannerMode: 'CLI'**
**    configMode: 'file'**
**    extraProperties: |**
**      coverageReportPaths: sonarqube-generic-coverage.xml**

- task: Xcode@5
  displayName: 'iOS Xcode build'
  inputs:
    actions: 'build'
    configuration: 'Release'
    sdk: 'iphoneos'
    xcWorkspacePath: 'FordTrucks.xcworkspace'
    scheme: 'FordTrucks'
    xcodeVersion: 'specifyPath'
    xcodeDeveloperDir: '/Applications/Xcode_13.0.app'
    packageApp: true
    signingOption: 'manual'
    signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
    provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)'

- task: Xcode@5
  displayName: 'iOS Xcode test'
  inputs:
    actions: 'test'
    configuration: 'Debug'
    sdk: 'iphoneos'
    xcWorkspacePath: 'FordTrucks.xcworkspace'
    scheme: 'FordTrucks'
    xcodeVersion: 'specifyPath'
    xcodeDeveloperDir: '/Applications/Xcode_13.0.app'
    packageApp: false
    useXcpretty: true
    publishJUnitResults: true
    testRunTitle: 'FordTruckiOS'
    destinationPlatformOption: 'iOS' # Optional. Options: default, iOS, tvOS, macOS, custom
    destinationPlatform: 'iOS Simulator'
    destinationTypeOption: 'simulators' # Optional. Options: simulators, devices
    destinationSimulators: 'iPhone 12' # Optional. Default value: iPhone8 for Xcode 11 and iPhone 7 for other iOS projects; Apple TV for tvOS projects.
    signingOption: 'manual'
    signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
    provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)'

**- task: Bash@3**
**  displayName: "Sonar Code Coverage"**
**  inputs:**
**    targetType: inline**
**    script: ./xccov-to-sonarqube-generic.sh ./DerivedData/Logs/Test/*.xcresult/ > ./sonarqube-generic-coverage.xml**

**- task: SonarQubeAnalyze@5**

**- task: SonarQubePublish@5**
**  inputs:**
**    pollingTimeoutSec: '300'**

- task: CopyFiles@2
  displayName: 'iOS copy ipa file to upload'
  inputs:
    SourceFolder: '$(system.defaultworkingdirectory)'
    Contents: '**/*.ipa'
    TargetFolder: '$(build.artifactStagingDirectory)'
    OverWrite: true
    flattenFolders: true
  condition: succeededOrFailed()

- task: PublishBuildArtifacts@1
  displayName: 'iOS publish ipa to artifacts'
  inputs:
    PathtoPublish: '$(build.artifactStagingDirectory)'
  condition: succeededOrFailed()

This is coverage report from sonarqube

Hi,

Welcome to the community!

Unfortunately, adding a coverage task to your ADO pipeline is a bit out of scope for this community.

 
Ann

Hi Ann,

Mac OS X: 12.4

I faced issue below line but I don’t know why. This is my local machine. Because this error is meaningless for me. This file is correct. Project is successfully build.

Log of execution:

Error point:

Error line of execution: (Empty line)

Also I added sonarqube-generic-coverage.xml file content a little bit auto created

Thanks in advance.

Best Regards.

Hi,

It looks like the file in question ends at line 59, but your Generic Coverage report includes something for line 60. It makes sense to me that analysis would error-out under those circumstances.

 
Ann

Hi,

I added empty line for check the line number of sonar analysis report. The line is empty. But I fixed my issue by running only sonar-scanner command with the line of ‘sonar.coverageReportPaths=sonarqube-generic-coverage.xml’ in sonar-project.properties file.

image

But I have already struggled with issue to sonar analysis report to sonar side. I added sonar zip file that contains sonarqube-generic-coverage.xml, xccov-to-sonarqube-generic.sh, run-sonar-swift.sh, sonar-project.properties (without login key) and all terminal log with executed sh file and bash command for generic coverage file.

Sonar.zip (115.1 KB)

Please help.

Hi,

I’m confused. This thread started with getting coverage into your analysis. Are you now shifting to this question of “no lines of code”? Because that’s a different thing and deserves a different thread.

 
Ann

Hi Ann,

Yes, right now I’m getting ‘no lines of code’. I will create new thread about ‘no lines of code’.

Although I have read all your documentation, I am very upset that you have experienced such a situation.

:frowning:

Hi,

It’s a shame you feel that way. This is free, community support and I’ve tried to be as helpful as I can. But whether you’re dealing with the community or our paid, professional support (yes, that’s available) we try to keep it to one topic per thread. Otherwise things tend to get messy, fast.

 
Ann

1 Like