简体   繁体   English

更新测试结果的构建参考 Azure DevOps REST API

[英]Update build reference for test result in Azure DevOps REST API

I have an existing test result and I'd like to update the "Tested build" field for the test result if possible.我有一个现有的测试结果,如果可能的话,我想更新测试结果的“已测试版本”字段。 I've looked at the REST API doc ( https://learn.microsoft.com/en-us/rest/api/azure/devops/test/results/update?view=azure-devops-rest-5.0 ) and I think that I've called the PATCH method correctly but while a 200 is returned, the test result in the UI doesn't change with "not available".我看过 REST API 文档( https://learn.microsoft.com/en-us/rest/api/azure/devops/test/results/update?view=azure-devops-rest-5.0 ),我认为我已经正确调用了 PATCH 方法,但是当返回 200 时,UI 中的测试结果不会随着“不可用”而改变。

Is there a way to change this field or is it read-only?有没有办法更改此字段或者它是只读的?

PATCH https://dev.azure.com/{org}/{project}/_apis/test/Runs/{runId}/results?api-version=5.0

Auth: PAT for user who has Test Plans license

JSON request body: 
[
    {
        "id": "100000",
        "build": {
            "id": "206",
            "name": {buildDefinitonName},
            "url": "https://dev.azure.com/{org}/{projectguid}/_apis/build/Builds/206"
        }
    }
]

JSON response body: 
{
    "count": 1,
    "value": [
        {
            "id": 100000,
            "project": {},
            "lastUpdatedDate": "2019-06-13T17:18:56.073Z",
            "priority": 0,
            "url": "",
            "lastUpdatedBy": {
                "displayName": null,
                "id": null
            }
        }
    ]
}

I've also tried with the .NET SDK but no luck:我也试过 .NET SDK 但没有运气:

...
var build = await buildClient.GetBuildAsync(projectGuid, 206);

var testResult = await testClient.GetTestResultByIdAsync(projectGuid, {runId}, 100000);

testResult.Build = new Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference
     {
         Id = build.Id.ToString(),
         Name = build.Definition.Name,
         Url = build.Url
     };

TestCaseResult[] results = new TestCaseResult[] { testResult };

var outcome = await testClient.UpdateTestResultsAsync(results, teamProject, {runId});

(outcome shows Build = null) (结果显示 Build = null)

I had similar problem, I checked with postman and this API works fine and updates the build into the test result.我有类似的问题,我检查了 postman 并且这个 API 工作正常并将构建更新到测试结果中。

Check if you need to set also into your call the build configuration as it is into the image.检查是否还需要在调用中设置构建配置,因为它在图像中。

On my case It works but it doesn´t work from the SDK not sure why I am still dealing with it.就我而言,它可以工作,但从 SDK 开始就无法工作,不确定为什么我仍在处理它。

Postman request Postman 请求

called the PATCH method correctly but while a 200 is returned, the test result in the UI doesn't change with "not available". 正确调用了PATCH方法,但是返回200时,UI中的测试结果不会更改为“ not available”。

To explain this, first need to know what does the response code 200OK defined: 为了解释这一点,首先需要知道响应代码200OK定义了什么:

" It represent a standard response for successful HTTP requests. The actual response will depend on the request method used. “它代表成功的HTTP请求的标准响应。实际响应将取决于所使用的请求方法。

As it say, 200OK just mean that your request URL, body and method are all correct and request successfully. 可以这样说, 200OK表示您的请求URL,正文和方法均正确无误,并且请求成功。 But, for actually put/patch action, it depend on the actual situation. 但是,对于实际的put/patch操作,这取决于实际情况。 So 200OK does not also mean that the operation is been completed and succeed. 因此200OK并不意味着该操作已完成并且成功。

在此处输入图片说明

So, for "Tested build" field for the test result in Azure Devops, 因此,对于Azure Devops中测试结果的“ Tested build”字段,

Is there a way to change this field or is it read-only? 有没有办法更改此字段,或者它是只读的?

No, you could not change it with API, even if with UI. 不,即使使用UI,也无法使用API​​进行更改。 It just read only. 它只是只读的。

You know, after test execution end, the build associated with this test is fixed, this is the actual truth. 您知道,在测试执行结束之后,与此测试关联的内部版本是固定的,这就是实际情况。 So, you could not change it, it just read only to tell you what is tested build. 因此,您无法更改它,它只能读以告诉您经过测试的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM