0

I have been able to generate Angular 4 code coverage in azure devops build pipeline.

Screenshot Of Generated Code Coverage

Screenshot Of Code Coverage Summary

But now I want to get the build coverage details from Azure DevOps Services REST APIs.

I am calling the REST API

https://dev.azure.com/{organization}/{project}/_apis/test/codecoverage?buildId={buildId}&flags={flags}&api-version=5.1-preview.1

of my azure build, as mentioned in

https://learn.microsoft.com/en-us/rest/api/azure/devops/test/code%20coverage/get%20build%20code%20coverage?view=azure-devops-rest-5.1.

But everytime I am getting {"value":[],"count":0} as response.

I need to get the coverage information from Azure DevOps Services REST API so that it can be appended in Email. Looking for help in this regard from this forum.

Shubho
  • 135
  • 1
  • 8
  • I found a workaround, see my answer here: https://stackoverflow.com/a/75454440/193634. I know I am not answering your question, but hopefully it helps someone. – Rosdi Kasim Feb 15 '23 at 00:21

1 Answers1

1

You can delete the flags parameter and make the url like this to check if the response body is your expected.

https://dev.azure.com/{orgname}/{projectname}/_apis/test/codecoverage?buildId={buildId}&api-version=5.1-preview.1

In addition, if you just want to append it in Email, you can use Publish code coverage results Task to get the codecoverage artifact and append this in Email. More detailed in formation about this task, you can refer to https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-code-coverage-results?view=azure-devops

Frank Wang-MSFT
  • 1,367
  • 6
  • 6
  • Thanks for the prompt reply, Frank. By removing the flags parameter, I am getting the result for branch coverage and line coverage. Is there any other api which can give more information on code coverage? – Shubho Oct 17 '19 at 05:53
  • Also the branch coverage that I am getting via this api is different from what is displayed in the build pipeline code coverage tab (screenshot updated in the question), but the line coverage is correct, any idea about this issue @Frank Wang-MSFT. ***Response Snippet*** -> *"coverageData":[ { "coverageStats":[ { "label":"Branches", "position":6, "total":9844, "covered":6179, "isDeltaAvailable":false, "delta":0.0 },* – Shubho Oct 18 '19 at 05:49
  • If you use Network tool to get the data, did the response data different from the data in the UI webpage? Like this.https://i.stack.imgur.com/w3N3f.png – Frank Wang-MSFT Oct 21 '19 at 09:29
  • Yes, Frank. The response data in network tool differs from what is there in UI, but only in case of branch coverage. In case of line coverage, the data is same, both in response and in UI. – Shubho Oct 22 '19 at 18:07
  • @Shubho, If convenience, could you please share a simple sample of your code about the branch test in onedrive? Then I can test it on my side and try to find a way to resolve it. – Frank Wang-MSFT Oct 23 '19 at 09:17
  • Actually, I am implementing this on my organization's build pipeline. So it's not possible to share the code. I will try the same process on a sample project and see whether I face the same problem or not. If I face the same problem, then I will get back to you with the sample code that I experiment on. – Shubho Oct 26 '19 at 06:46