我正在使用用于 Azure DevOps 的 .NET 客户端库来从构建尝试中获取测试结果。以下抛出身份验证错误,Microsoft.VisualStudio.Services.Common.VssUnauthorizedException: VS30063: You are not authorized to access https://dev.azure.com.
var testClient = connection.GetClient<TestManagementHttpClient>();
var testResults = await testClient.GetTestResultsByBuildAsync2(
project: project,
buildId: ID);
我使用的 PAT 的作用范围是读取和执行构建和测试。不知道为什么我会收到此错误。还有其他方法可以获取每次尝试的测试结果吗?我可以使用相同的连接来调用 GetTestResultDetailsForBuildAsync
,但不幸的是,它列出了所有尝试的结果,我只需要最后一个。
Microsoft.VisualStudio.Services.Common.VssUnauthorizedException: VS30063: You are not authorized to access https://dev.azure.com.
错误:
参考:
- 按照
Marina Liu的建议清理缓存:执行
regedit
-> 清除下面的键HKEY_CURRENT_USER\Software\Microsoft\VSCommon\14.0\ClientServices\TokenStorage\VisualStudio\VssApp
-> 重新启动 VS -> 使用您自己的凭据运行您的项目。- 检查个人访问令牌是否已过期或使用正确的范围创建
VS30063:您无权访问 https://dev.azure.com?尝试使用 PAT 令牌在 Azure DevOps 项目中注册专用代理池时出错 - Microsoft Q&A、c# - VS30063:您无权访问 https://dev.azure.com - Stack Overflow 和 Visual Studio 反馈
GetTestResultsByBuildAsync
。 幸运的是,我注意到有不同类型的客户:
TestResultsHttpClient testClient1 = connection.GetClient<TestResultsHttpClient>();
TestManagementHttpClient testClient2 = connection.GetClient<TestManagementHttpClient>();
如果我使用testClient1
,那么调用下面的代码工作正常,但当我使用
testClient2
时,会因身份验证错误而失败。:
List<ShallowTestCaseResult> allTestResults =
await testClient.GetTestResultsByBuildAsync(ProjectName, buildId);
请尝试使用TestResultsHttpClient
代替
TestManagementHttpClient
。