使用 Javascript REST API 在 TFS 中创建大量工作项 [英] Create Large Amount of Work Items in TFS Using Javascript REST API
问题描述
我需要通过我的 TFS 扩展创建大约 6000 个工作项.我在我的扩展中使用了 typescript 和 REST API.
下面是我用来创建工作项的代码
var ops = [{路径:/fields/System.Title",操作:添加",值:你好世界"}];变量选项 = {url: 'http://localhost:8080/tfs/DefaultCollection/Agile Git/_apis/wit/workItems/$Bug?api-version=2.2',用户名:'用户名',密码:'密码',域:'域',方法:'补丁',标题:{'内容类型':'应用程序/json-patch+json'},正文:JSON.stringify(ops)};httpntlm.patch(options, function(err,res) {console.log("补丁完成");控制台日志(res.body);})
我迭代每个工作项的详细信息,并尝试以时间间隔(例如 100 个工作项批次)创建大量工作项.但是对于许多存在超时问题的工作项,创建过程失败(我能够生成大约 1000 个工作项).是否有推荐的方法来创建/编辑工作项.请帮忙.
改用工作项批处理 api:
例如:
http://[collection url]/_apis/wit/$batch?api-version=1.0
身体:
<预><代码>[{"方法": "补丁","uri": "/ScrumStarain/_apis/wit/workItems/$Product Backlog Item?api-version=1.0",标题":{内容类型":应用程序/json-patch+json"},身体": [{"op": "添加","path": "/fields/System.Title",值":api1"},{"op": "添加","路径": "/id",值":-1"}]},{"方法": "补丁","uri": "/ScrumStarain/_apis/wit/workItems/$Task?api-version=1.0",标题":{内容类型":应用程序/json-patch+json"},身体": [{"op": "添加","path": "/fields/System.Title",值":api2"},{"op": "添加","路径": "/id",值":-2"}]}]更多信息,可以参考:工作项批处理操作
I need to create around 6000 work items via my TFS extension. I use typescript and REST API in my extension.
below is the code I use to create work item
var ops = [
{
path: "/fields/System.Title",
op: "add",
value: "Hello world"
}
];
var options = {
url: 'http://localhost:8080/tfs/DefaultCollection/Agile Git/_apis/wit/workItems/$Bug?api-version=2.2',
username: 'username',
password: 'password',
domain: 'domain',
method: 'PATCH',
headers: {
'Content-Type': 'application/json-patch+json'
},
body: JSON.stringify(ops)
};
httpntlm.patch(options, function(err,res) {
console.log("patch complete");
console.log(res.body);
})
I iterate details for each work item and try to create bulk of work items, with time intervals (like 100 work items batches) . But creation process fails for many of work items with timeout problems (I was able to generate around 1000 work items). Is there recommended method to create / edit work items. Please help.
Using Work item batch api instead:
For example:
http://[collection url]/_apis/wit/$batch?api-version=1.0
Body:
[
{
"method": "PATCH",
"uri": "/ScrumStarain/_apis/wit/workItems/$Product Backlog Item?api-version=1.0",
"headers": {
"Content-Type": "application/json-patch+json"
},
"body": [
{
"op": "add",
"path": "/fields/System.Title",
"value": "apip1"
},
{
"op": "add",
"path": "/id",
"value": "-1"
}
]
},
{
"method": "PATCH",
"uri": "/ScrumStarain/_apis/wit/workItems/$Task?api-version=1.0",
"headers": {
"Content-Type": "application/json-patch+json"
},
"body": [
{
"op": "add",
"path": "/fields/System.Title",
"value": "apip2"
},
{
"op": "add",
"path": "/id",
"value": "-2"
}
]
}
]
More information, you can refer to: Work item batch operations
这篇关于使用 Javascript REST API 在 TFS 中创建大量工作项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!