如何使用 Node.js 的 Visual Studio Team Services 客户端 (vso-node-api) 创建工作项?

Ban*_*ara 0 tfs-sdk node.js azure-devops azure-pipelines-build-task azure-pipelines

我需要使用 Node.js 的 Visual Studio Team Services 客户端 (vso-node-api) 创建 VSTS 工作项,请提供相关示例吗?

Edd*_*SFT 5

我创建了一个简单的代码示例来获取和创建工作项,供您参考,有关详细信息,请参阅以下部分:

/// <reference path="typings/index.d.ts" />

import * as vm from 'vso-node-api/WebApi';
import * as wa from 'vso-node-api/WorkItemTrackingApi';
import * as wi from 'vso-node-api/interfaces/WorkItemTrackingInterfaces';
import * as vss from 'vso-node-api/interfaces/Common/VSSInterfaces';

var collectionUrl = "https://xxxxxx.visualstudio.com";

let token: string = "Yourpersonalaccesstoken";

let creds = vm.getPersonalAccessTokenHandler(token);

var connection = new vm.WebApi(collectionUrl, creds); 

let vstsWI: wa.IWorkItemTrackingApi = connection.getWorkItemTrackingApi();

async function getWI() {
    let wiid: number = 1;
    let workitem: wi.WorkItem = await vstsWI.getWorkItem(wiid);

    console.log(workitem.url);
}

getWI();

async function createWI() {
    let wijson: vss.JsonPatchDocument = [{ "op": "add", "path": "/fields/System.Title", "value": "Task created from Node JS" }];
    let project: string = "Project";
    let witype: string = "Task";
    let cWI: wi.WorkItem = await vstsWI.createWorkItem(null, wijson, project, witype);
    console.log(cWI.id);
}

createWI();
Run Code Online (Sandbox Code Playgroud)