- Step: Read out the runs of your buildpipeline to get the run id - link
Url:
GET http://{instance}/{collection}/{project}/_apis/test/runs?api-version=5.0
- Step: Read out the results of a specific run - link
Url:
GET https://{instance}/{collection}/{project}/_apis/test/Runs/{runId}/results/{testCaseResultId}?api-version=5.0
- Step: analyse the response
from step 2 you will get a Json respone with the struct:
"startedDate": "2019-07-26T04:42:59.097Z",
"completedDate": "2019-07-26T04:42:59.107Z",
"durationInMs": 10,
"outcome": "Passed",
"revision": 1,
"state": "Completed",
"testCase": {
"name": "TestConstructorDescriptor"
},
"startedDate": "2019-07-31T09:07:51.153Z",
"completedDate": "2019-07-31T09:07:51.153Z",
"outcome": "Failed",
"revision": 1,
"state": "Completed",
"testCase": {
"name": "TestCreateTelegrams"
},
- Step: Filter tests with
Failed
outcome and store the meta information in an array
- Step: Create your Workitem - link
Payload:
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Sample task"
}
]
Url:
POST https://{instance}/{collection}/{project}/_apis/wit/workitems/${type}?api-version=5.0
Wrap all these steps in a script (PowerShell) and added to your buildpipeline after VsTest Task. These snippets may help:
Authorization headers: (Personal Access Token needed)
#AUTHORIZATION HEADERS
$headers = @{
"Authorization" = ('Basic {0}' -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)")))
"If-Match" = ""
}
REST API Invoke-RestMethod: (Edit -Method GET or POST
)
$url = "<Enter url from steps 1, 2 or 5>"
$projs = Invoke-RestMethod -Uri $url -Method GET -ContentType "application/json" -Headers $headers -Verbose
Create Payload:
$json = @{ "op" = "add"; "path" = "$path"; ... } | ConvertTo-Json
Get ETag: (may needed for PUT
or POST
methods, execute before Invoke-RestMethod)
$request = Invoke-WebRequest -Uri $url -Method GET -ContentType "application/json" -Headers $headers -Verbose
$headers.'If-Match' = $request.Headers.ETag
Hope this helps.