【发布时间】:2020-05-05 07:44:56
【问题描述】:
我正在为 azure devops 创建一个扩展,它会创建一个自定义选项卡并显示结果。
我使用“##vso[task.addattachment]”上传了文件。
例如:console.log('##vso[task.addattachment type=TestReport;name=MyReport;]c:/user/index.html');
我在使用该文件并将其显示在新选项卡上时遇到问题,我浏览了 MS 提供的示例代码 - build_release_enhancer 但仍然无法显示文件。
js 文件::
import Controls = require("VSS/Controls");
import VSS_Service = require("VSS/Service");
import TFS_Build_Contracts = require("TFS/Build/Contracts");
import TFS_Build_Extension_Contracts = require("TFS/Build/ExtensionContracts");
import DT_Client = require("TFS/DistributedTask/TaskRestClient");
import { error } from "azure-pipelines-task-lib";
export class InfoTab extends Controls.BaseControl {
constructor() {
super();
}
public initialize(): void {
super.initialize();
// Get configuration that's shared between extension and the extension host
var sharedConfig: TFS_Build_Extension_Contracts.IBuildResultsViewExtensionConfig = VSS.getConfiguration();
var vsoContext = VSS.getWebContext();
if(sharedConfig) {
// register your extension with host through callback
sharedConfig.onBuildChanged((build: TFS_Build_Contracts.Build) => {
this._initBuildInfo(build);
var taskClient = DT_Client.getClient();
taskClient.getPlanAttachments(vsoContext.project.id, "build", build.orchestrationPlan.planId,"ATTACHMENT_TYPE_HERE").then((taskAttachments) => {
$.each(taskAttachments, (index, taskAttachment) => {
if (taskAttachment._links && taskAttachment._links.self && taskAttachment._links.self.href) {
var recId = taskAttachment.recordId;
var timelineId = taskAttachment.timelineId;
taskClient.getAttachmentContent(vsoContext.project.id, "build", build.orchestrationPlan.planId,timelineId,recId,"ATTACHMENT_TYPE_HERE",taskAttachment.name).then((attachementContent)=> {
function arrayBufferToString(buffer){
var arr = new Uint8Array(buffer);
var str = String.fromCharCode.apply(String, arr);
return str;
}
var data = arrayBufferToString(attachementContent);
});
}
});
});
});
}
}
private _initBuildInfo(build: TFS_Build_Contracts.Build) {
}
}
InfoTab.enhance(InfoTab, $(".build-info"), {});
// Notify the parent frame that the host has been loaded
VSS.notifyLoadSucceeded();
HTML 文件:
<!DOCTYPE html>
<head>
<script src="../lib/VSS.SDK.min.js"></script>
<script type="text/javascript">
VSS.init( {
usePlatformScripts: true,
// moduleLoaderConfig: {
// paths: { "sample": "sample" }
// }
});
VSS.ready(function() {
require(["sample/tab2"], function () { });
});
</script>
<style>
.build-info {
padding: 10px;
}
</style>
</head>
<body>
<div class="build-info"> </div>
</body>
</html>
【问题讨论】:
-
您的意思是使用扩展程序在新选项卡中显示测试结果附件吗?
-
@AndyLi-MSFT 是正确的。
-
现在我已经创建了自定义选项卡并显示了一些静态 html 数据。而不是静态的,我想显示测试结果。
-
我认为您需要检查 Get Test Result Attachments 或 Get Test Run Attachments REST API。还要检查这个线程是否有帮助:How to get unit test results using TFS Rest API?
-
感谢您的回复,问题已解决,实际上问题出在我的 vss-extension.json 文件上。我必须声明范围,“范围”:[“vso.build_execute”],非常感谢您调查它。
标签: javascript tfs azure-devops azure-pipelines azure-pipelines-build-task