问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/42523355/create-large-amount-of-work-items-in-tfs-using-javascript-rest-api