function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kit OsipenkoKit Osipenko 

Code Coverage Cobertura

I need to publish code coverage to Azure DevOps build pipeline. It needs ot be in Cobertura or JaCoCo format. Are there any tools I could use to convert current format into somehting that AzureDO can process?

I execute this command to generate code coverage:

sfdx force:apex:test:run --wait 10 --resultformat junit --codecoverage

test results are viewable in the pipeline, but not coverage...
VinayVinay (Salesforce Developers) 
Hi Kit,

Check below reference.

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-code-coverage-results?view=azure-devops
https://dejanstojanovic.net/aspnet/2020/may/setting-up-code-coverage-reports-in-azure-devops-pipeline/

Thanks,
Kit OsipenkoKit Osipenko
Trust me, I know how to setup code coverage in Azure DevOps. The format (.json) generated by sfdx utility is not supported by Azure DevOps. Does anyone have experience importing code coverage generated by sfdx into Azure DevOps?
Marcelo CostaMarcelo Costa

Hey Kit, I had the same issue as you, so I created a sfdx plugin to convert SF report into jacoco report that can be read from ADO.

To use it: In your pipeline, download the plugin by adding a bash step with the command:

echo "y" | sfdx plugins:install sfciutils;

After that you run the following sfdx command:

sfdx ciutils:testclass:convertCovToJacoco -i [path to your SF reports folder] > [path and filename where you want to save the jacoco report]

After that, you create the publish coverage task:

- task: PublishCodeCoverageResults@1
            inputs:
              codeCoverageTool: 'JaCoCo' # Available options: 'JaCoCo', 'Cobertura'
              summaryFileLocation: [Path and file ref to the jacoco converted report]
              pathToSources: [path to your classes folder]
              reportDirectory: [where you want to save the html reports]
              #additionalCodeCoverageFiles: # Optional
              #failIfCoverageEmpty: false # Optional


It is working for me just great, If you want to try and have issues, feel free to reach out and I can try to troubleshoot the script (As is still in an alpha stage)
Cheers And good Luck!

 

Shaindy EilenbergShaindy Eilenberg
Hey @Marcelo Costa,
I'm trying to use your solution, looks cool!
But it seems that the task does not know how to handle the XML I receive
The code coverage looks like this:
User-added image
You have an idea why this is happening?

Thanks!
fly2nadeem Demofly2nadeem Demo
Hey @Marcelo Costa,
I have tried your utility "ciutils" and it seems it need some modification and correction as it is giving error.
Request you to kindly guide us to resolve the issue.


Below are the issue which I'm facing and some workaround which I have perform till now to use the utility. 

1. The utility is trying to search the test-result.xml which has been deprecated and been replaced by test-result-<testrunid>-junit.xml (https://developer.salesforce.com/blogs/2021/04/clearer-apex-commands)
2. To Over come this issue I have created Copy and File rename TASK in Azure DevOps Pipeline.
  • Copy Task - It will create a separate folder and copy the test-result-<testrunid>-junit.xml to this folder
  • File Re-Name Task - This will rename test-result-<testrunid>-junit.xml to test-result.xml.
3. After step 1 and 2, the Utility started working and even generated the out-put file in .xml format (in my case it is abc.xml)
4. But when we create "Publish code coverage results Task" it give me error as below error

" Reading code coverage summary from '/home/vsts/work/1/s/result/codecoverage/abc.xml'
##[warning]Failed to read /home/vsts/work/1/s/result/codecoverage/abc.xml. Error : Data at the root level is invalid. Line 1, position 1..
##[warning]No coverage data found. Check the build errors/warnings for more details. "

  - task: PublishCodeCoverageResults@1
    inputs:
      codeCoverageTool: 'JaCoCo'
      summaryFileLocation: '$(System.DefaultWorkingDirectory)/result/codecoverage/abc.xml'
      pathToSources: '$(System.DefaultWorkingDirectory)'
      reportDirectory: '$(System.DefaultWorkingDirectory)/result/codecoverage'