1
votes

I have a VsTest task in a build definition, which generates a .coverage file that can be downloaded using the "Download Code Coverage Results" link. I then use ReportGenerator to create HTML reports from it. Works great.

Now I'd like to add a script task to run the ReportGenerator on the server, but I haven't been able to figure out how to actually reference the .coverage file. Each run is different, with a path like:

"C:\agent\_work\1\s\TestResults\0195053f-05f0-40a5-bfae-a0215dd0af80\WIN-JQJJSGM4KOU$_WIN-JQJJSGM4KOU 2018-04-13 06_50_42.coverage"

The first part of the path seems to be $(Common.TestResultsDirectory), but what is 0195053f-05f0-40a5-bfae-a0215dd0af80? An identity probably, but which one?

Microsoft has a nice Build Variables page, which I'll look into more later, but hoping someone has already figured this out.

1
You should be able to use the REST API to get the path to this file for each build. If you do it that way, the dynamic part won't matter. You can grab the path and then pass it in to your report generator. I would start there.tehbeardedone
@tehbeardedone No idea how to do that, but it sounds promising. Will give it a go. Thanks.Chris Olsen
If I had more time I would drum up an example. You may need to publish the results first and then you should be able to get the build artifacts using the REST API. I can't remember exactly how to do it but I know it can be done. It's been awhile since I had to do this but I used to use dotcover to generate a coverage report and then I would use the API to pull down that file and convert it into a format I needed it to be in. I'm pretty confident it can be done you just may need to dig around a bit to figure it out.tehbeardedone
Do you solve this issue?starian chen-MSFT
Partially. Wrote some ps, and learned a bit more about VSTS, but haven't had time yet to pull it all together into a working solution for generating coverage reports in a VSTS build definition.Chris Olsen

1 Answers

2
votes

There isn’t the built-in variable of VSTS build to get Code Coverage Results, it searches file. So you can search files in TestResults folder (per to file suffix) through PowerShell (e.g. Get-Childitem: Use Windows PowerShell to search for files), the value of $(Build.SourcesDirectory) variable is C:\agent\_work\1\s.