1
votes

I am running some test in a containerize environment in Azure and I want to publish those test results in Azure Devops related to its release.

The idea is that the testcases are running in a Release Pipeline, and the container it self when its finished it will publish the test and display them in the tests section of Azure Devops.

I have managed to do this with mounted volumes on the container and with the Publish test task in the pipeline. But the tests takes around 1h and during that time its taking one pipeline agent in Azure.

I have been looking into Azure Devops API and managed to create a new testrun and add test to it through the API. I have related the testrun to the release by its ID https://docs.microsoft.com/en-us/rest/api/azure/devops/test/runs/create?view=azure-devops-rest-5.0. And afterwards added the completed tests results into the test run. However is not displayed on the releases tests.

enter image description here

Any one faced this issue?

Updated end rest API.

Here I obtain the release ID (I expect I will be able to get this release ID during the release pipeline)

curl --location --request GET 'https://vsrm.dev.azure.com/{organization}/NF Development/_apis/release/releases?api-version=6.0'

I create a test run related with this release

curl --location --request POST 'https://dev.azure.com/{organizationname}/NF Development/_apis/test/runs?api-version=5.0' \

--header 'Content-Type: application/json' \
--data-raw '{
 "name": "Testcafe new", 
 "ReleaseReference": { "id": "1276" }, 
 "isAutomated": true, 
 "state": "Waiting" 
}'

I add test to the test run I obtain in the container.

curl --location --request POST 'https://dev.azure.com/{organizationname}/NF Development/_apis/test/Runs/1004040/results?api-version=6.0' \
--header 'Content-Type: application/json' \
--data-raw '[{
    "testCaseTitle": "Testing Tescafe through Azure API",
    "automatedTestName": "Patrick Test",
    "priority": 1,
    "outcome": "Passed"
  }
  ]'

It this point I can see the test run in the in the test plants, however the tests section inside the release it empty.

----------------------- EDIT ----------------------

Maybe my request was not clear. What I want to achieve is what the publish result is doing through the release pipeline, but using AzureDevops pipeline.

enter image description here

Here for example I have this task running, and I can click on the test tab for the release environment and identify all the test from my build. Even that I create a TestRun as described below I cant see this happening.

1
Can you provide an example of your REST API request body? In particular, how do you set releaseReference?Jane Ma-MSFT
@JaneMa-MSFT Hi Jane, I updated the post with the REST API I have used. The first step in order to obtain the release ID is going to be done inside the release pipeline.Patrick Vibild
@JaneMa-MSFT I was checking today more into this issue, I was checking pipelines and AzureDevops documentation. What I am looking is to do exactly what 'Publish Test Results task' is doing inside the release pipeline through the AzureDevops API so I can link 1:1 test runs to the releases.Patrick Vibild
Hi there, is there any updates for this issue? Please check whether my answer below can help you and feel free to comment~ If you want to know whether your test run is properly connected to the release, go to Test Plans -> Runs and double click your test run to get its detailed information.Jane Ma-MSFT
Hi Jane. Thanks for your input. I have put this to the side for a week or so. I will test this next week. Thanks a lot for your followup.Patrick Vibild

1 Answers

1
votes

The possible reason for this question is that your test run is not properly linked to the release.

In the Runs - Create Rest API, not only you need to specifie the Release id, but the release uri, release environment id and release enviornment uri must be specified as well.

Here is an example about creating a test run which is linked to a release:

{
  "name": "A",
  "plan": {
    "id": {Test Plan id}
  },
   "releaseReference":{
      "id": {release id},
      "name": "{Release name}",
      "definitionId": {Release definition ID},
      "environmentDefinitionId": {Release environment definition ID},
      "environmentName": "{Release environment name}",
      "environmentDefinitionName": "{Release environment definition name}",
      "environmentId": {Release environment ID}
   },
   "releaseUri": "{URI of release associated with the run}",
   "releaseEnvironmentUri": "{URI of release environment associated with the run}"
   "state": "Waiting"
}