Azure Devops(vsts)费用-如何创建任务附件内容

问题描述 投票:0回答:1

我正在为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>
javascript tfs azure-devops azure-pipelines azure-pipelines-build-task
1个回答
0
投票

问题已解决,实际上问题出在我的vss-extension.json文件中。我必须声明范围:

"scopes": [
    "vso.build_execute"
]
© www.soinside.com 2019 - 2024. All rights reserved.