Reputation: 2494
My code is hosted in GitHub and I run CI builds in VSTS with VSTest which outputs code coverage results. I can see these results in the finished build page, but it would be nice to be able to display these on our GitHub repo like our build status badge and nuget badges are. Does anyone know of a standard way to do this with VSTS (i.e. built in task) or is this something I would need to handle in a script myself?
Upvotes: 1
Views: 607
Reputation: 38136
To show VSTS build results (such as code coverage results) on README, you need to handle it by your own script.
The main idea is get related information for build logs and commit the information in README.
Deatil steps as below:
Add a PowerShell task at the end of your CI build definition
In powershell script, you need to get test results from build logs, format and commit the information in README. Finally push the changes to your github repo. Functions in the powershell script need to be achieved as following steps.
Get related build logs
You can get the current build logs by using Timeline REST API:
GET https://account.visualstudio.com/project/_apis/build/builds/$(Build.BuildId)/timeline?api-version=4.1
And you can search logs of a certain test by task name (such as VSTest
):
{
"id": "407545ba-79a9-55a7-47dd-583380011305",
"parentId": "df143ba0-1c7a-5b21-02e1-d41a394e29c9",
"type": "Task",
"name": "VsTest - testAssemblies",
"startTime": "2018-05-01T08:20:45.3233333Z",
"finishTime": "2018-05-01T08:21:55.3733333Z",
"currentOperation": null,
"percentComplete": null,
"state": "completed",
"result": "succeeded",
"resultCode": null,
"changeId": 14,
"lastModified": "0001-01-01T00:00:00",
"workerName": "WXV-XINDO-12R2",
"order": 4,
"details": null,
"errorCount": 0,
"warningCount": 0,
"url": null,
"log": {
"id": 5,
"type": "Container",
"url": "https://marinaliu.visualstudio.com/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/2897/logs/5"
},
"task": {
"id": "ef087383-ee5e-42c7-9a53-ab56c98420f9",
"name": "VSTest",
"version": "1.0.86"
}
Then you can get the VSTest build log by the url https://marinaliu.visualstudio.com/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/2897/logs/5 (as above example).
Collect the information and format README
You can get the information for your needs, and format the README file.
Commit and push changes to your github repo
git checkout $(Build.SourceBranchName)
git add .
git commit -m 'update README'
git push origin $(Build.SourceBranchName)
Note:
And since git command usually show non-standard output, you need to deselect Fail on Standard Error option for PowerShell task.
Upvotes: 1