How to create work items using Visual Studio Team Services Client for Node.js (vso-node-api)?

时间秒杀一切 提交于 2019-11-28 12:23:03

问题


I need to create VSTS work items using Visual Studio Team Services Client for Node.js (vso-node-api), Please provide any samples on this?


回答1:


I created a simple code sample to get and create work item with it for your reference, see following section for details:

/// <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();



回答2:


Use the token retrieved using vsts-task-lib

import tl = require('vsts-task-lib/task');
let auth = tl.getEndpointAuthorization("SYSTEMVSSCONNECTION", false);
var token = auth.parameters["AccessToken"];


来源:https://stackoverflow.com/questions/39631747/how-to-create-work-items-using-visual-studio-team-services-client-for-node-js-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!