gpt4 book ai didi

tfs - VSTS 扩展 - 从构建任务存储参数并从摘要选项卡调用 Web 服务

转载 作者:行者123 更新时间:2023-12-04 12:18:49 26 4
gpt4 key购买 nike

我需要在摘要选项卡(“ms.vss-build-web.build-results-section”)中显示自定义构建任务的结果。为了做到这一点,我需要从构建任务中保留一些数据,并使用它从摘要部分调用 Web 服务。是否可以使用扩展数据服务将数据存储在变量中并在摘要页面中使用它?最好的方法应该是什么?

提前致谢。

最佳答案

我已经使用 Logging 命令附加了我的构建任务数据

https://github.com/Microsoft/vsts-tasks/blob/986f8f5112017474962affe58c9ebaf394fb9354/docs/authoring/commands.md

//Build Task

class TestClass {
_name: string;
_age: number;

constructor(name: string, age:number) {
this._name = name;
this._age = age;
}
}

var data = new TestClass(TinTin,100);

//Create a folder
tl.mkdirP("c:/myfolder/");

//Write data to a file
tl.writeFile("c:/myfolder/mydata.txt",JSON.stringify(data));

//Executes command to attach the file to build
console.log("##vso[task.addattachment type=myAttachmentType;name=myAttachmentName;]c:/myfolder/mydata.txt");


从摘要页面检索附件。

https://github.com/Microsoft/vsts-extension-samples/blob/master/build-results-enhancer/src/enhancer/tab.ts

//Summary Page

/// <reference path="../definitions/Q.d.ts" />
/// <reference path="../definitions/vss.d.ts" />
/// <reference path="../definitions/tfs.d.ts" />
/// <reference path="../definitions/jquery.d.ts" />

import VSS_Service = require("VSS/Service");
import Controls = require("VSS/Controls");
import TFS_Build_Contracts = require("TFS/Build/Contracts");
import TFS_Build_Extension_Contracts = require("TFS/Build/ExtensionContracts");
import DT_Client = require("TFS/DistributedTask/TaskRestClient");

export class StatusSection 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) => {

var taskClient = DT_Client.getClient();
taskClient.getPlanAttachments(vsoContext.project.id, "build", build.orchestrationPlan.planId, "myAttachmentType").then((taskAttachments)=> {

if (taskAttachments.length === 1) {
var recId = taskAttachments[0].recordId;
var timelineId = taskAttachments[0].timelineId;

taskClient.getAttachmentContent(vsoContext.project.id, "build", build.orchestrationPlan.planId,timelineId,recId,"myAttachmentType","myAttachmentName").then((attachementContent)=> {
function arrayBufferToString(buffer){
var arr = new Uint8Array(buffer);
var str = String.fromCharCode.apply(String, arr);
if(/[\u0080-\uffff]/.test(str)){
throw new Error("this string seems to contain (still encoded) multibytes");
}
return str;
}

var summaryPageData = arrayBufferToString(attachementContent);

//Deserialize data
var ob = JSON.parse(summaryPageData);
console.log("Name: " + ob._name);
console.log("Age: " + ob._age);

});
}
});
});
}
}
}

StatusSection.enhance(StatusSection, $(".build-status"), {});

// Notify the parent frame that the host has been loaded
VSS.notifyLoadSucceeded();

关于tfs - VSTS 扩展 - 从构建任务存储参数并从摘要选项卡调用 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39031367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com