1

I am working on creating an extension for azure devops, which creates a custom tab and displays the result.

I uploaded the file using "##vso[task.addattachment]".

Eg: console.log('##vso[task.addattachment type=TestReport;name=MyReport;]c:/user/index.html');

I am having problem in consuming that file and displaying it on new tab, I went through the sample code provided by MS - build_release_enhancer but still unable to display the file.

js file::

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 file:

<!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>
Abhishek Anvekar
  • 338
  • 1
  • 5
  • 18
  • Do you mean show the test result attachments in a new tab by using the extension? – Andy Li-MSFT Jan 20 '20 at 10:25
  • @AndyLi-MSFT yes correct. – Abhishek Anvekar Jan 20 '20 at 11:22
  • right now I have create custom tab and displayed some static html data. Instead of static I would like to display the test result. – Abhishek Anvekar Jan 20 '20 at 11:26
  • I think you need to check the [Get Test Result Attachments](https://learn.microsoft.com/en-us/rest/api/azure/devops/test/attachments/get%20test%20result%20attachments?view=azure-devops-rest-5.1) or [Get Test Run Attachments](https://learn.microsoft.com/en-us/rest/api/azure/devops/test/attachments/get%20test%20run%20attachments?view=azure-devops-rest-5.1) REST APIs. Also check if this thread helps : [How to get unit test results using TFS Rest API?](https://stackoverflow.com/questions/39373499/how-to-get-unit-test-results-using-tfs-rest-api) – Andy Li-MSFT Jan 21 '20 at 10:22
  • Thank you for responding, the issue is resolved, actually the issue was with my vss-extension.json file. I had to declare scope, "scopes": [ "vso.build_execute" ], thank you so much for looking into it. – Abhishek Anvekar Jan 21 '20 at 12:00

1 Answers1

1

The issue is resolved, actually the issue was with my vss-extension.json file. I had to declare scope:

"scopes": [
    "vso.build_execute"
]
Abhishek Anvekar
  • 338
  • 1
  • 5
  • 18
  • Thanks for sharing the solution. You could [Accept it as an Answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work), This can be beneficial to other community members reading this thread. – Andy Li-MSFT Jan 21 '20 at 15:24