I want to attach a work item on tfs to a build. i am reading SVN logs which contain the work item number and try to update the actual build to attach them.
workitems.Add(workItemStore.GetWorkItem(workitemid));
buildDetail.Information.AddAssociatedWorkItems(workitems.ToArray());
When I try to hit buildDetail.Information.Save();
or buildDetail.Save();
, I get an AccessDeniedException
.
See another post.
So I wanted to try with REST... After loads of pages on MSDN, I concluded there is no .NET Client Library that takes care of builds. It looks like my only option is to patch a json into the TFS:
PATCH https://{instance}/DefaultCollection/{project}/_apis/build/builds/{buildId}?api-version={version}
How do I add the workitems the right way?
EDIT: I've found an old post which mentioned a dll in the TFS namespace which has the same capabilities like the call from above. Unluckily, it's not refered in MSDN. Same problem here: no way to add workitems.
To spread the issue and adress it to MS: Patrick has created a post on uservoice
UPDATE:
I managed to link a build in the work item. Here is an approach in c#:
var json = new JsonPatchDocument
{
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations/-",
Value = new WorkItemRelation()
{
Rel = "ArtifactLink",
Url = build.Uri.ToString()
}
}
};
var client = new WebClient { UseDefaultCredentials = true };
client.Headers.Add(HttpRequestHeader.ContentType, "application/json-patch+json");
client.UploadData(
options.CollectionUri + "/_apis/wit/workitems/" + workitemid + "?api-version=1.0",
"PATCH",
Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(json)));
But there is still no direct binding in the build:
And the work items says unknown executable linktype
According to the message given in the workitem, I assume that I am using the false linktype. Does anybody have a reference for me, what types I am able to and should use?
URI UPDATE:
I am already using the mentioned uri:
MINOR SOLUTION:
I had to add the name "Build" to the Attributes of the patch. I still does not recognize it in the build itself but for now, I can work with the link as build type.
var json = new JsonPatchDocument
{
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations/-",
Value = new WorkItemRelation()
{
Rel = "ArtifactLink",
Url = build.Uri.ToString()
Attributes = new Dictionary<string, object>()
{
{ "name", "Build" },
{ "comment", build.Result.ToString() }
}
}
}
};