Reputation: 37000
I try to get the changes between two builds using this code:
var changes1 = buildClient.GetChangesBetweenBuildsAsync("PipelineTest", 2, 3).Result;
This returns no elements. However when I try to get the changes via the web-portal for build 3 I get a change:
I also tried build.GetBuildChangesAsync("PipelineTest", 3)
which gave me no results neither.
I have to notice thogh, that the pipeline is stored within Repo1
, whereas the change was done on Repo2
.
How can I get all changes between two builds regardless on the repository they have been committed in?
I am using TeamFoundationServer.Client
16.170.0
Upvotes: 0
Views: 1223
Reputation: 37000
As we already found out getting the changes or workitems between two builds on a multi-repository-structure isn't yet supported on Azure Devops. There's a feature-request for that, though.
In order to workaround that I inspected how the graphical interface retrieves the information and noticed there is some undocumented function called HierarchyQuery
. After some trial and error I got that function to work within my app. There are a couple of information we need to provide here, though.
The first of course is some authentication - in my example I use a private access token. This is identical to authenticating the "normal" API. The second point here is some data that we should use in our POST-request. This mainly contains the repo for which we want to get changes ("artifactAlias":"Repo2"
) as well as the build-id we want to inspect ("currentRunId":3
). As we have multiple repos, we need to loop them, which I omited here, you get the idea, don't you?
Lastly we need to parse the response in order to get the workitemid. From there we can again use the normal API to query the associated item.
However notice this is completely undocumented and no public API.
string workItemId;
var json = "{\"contributionIds\":[\"ms.vss-traceability-web.traceability-workitems-data-provider\"],\"dataProviderContext\":{\"properties\":{\"artifactAlias\":\"Repo2\",\"currentRunId\":3,\"useSnapshot\":true,\"sourcePage\":{\"url\":\"https://dev.azure.com/myorganization/PipelineTest/_traceability/runview/workitems?currentRunId=3\",\"routeId\":\"ms.vss-traceability-web.traceability-run-workitems-hub-default-route\",\"routeValues\":{\"project\":\"PipelineTest\",\"controller\":\"ContributedPage\",\"action\":\"Execute\",\"serviceHost\":\"MyServiceHost\"}}}}}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.ParseAdd("application/json;api-version=5.0-preview.1;excludeUrls=true;enumsAsNumbers=true;msDateFormat=true;noArrayWrap=true");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", myPAT))));
using (HttpResponseMessage response = client.PostAsync("https://dev.azure.com/myorganization/_apis/Contribution/HierarchyQuery", content).Result)
{
response.EnsureSuccessStatusCode();
string responseBody = response.Content.ReadAsStringAsync().Result;
dynamic r = JsonConvert.DeserializeObject(responseBody);
workItemId = (string)r["dataProviders"]["ms.vss-traceability-web.traceability-workitems-data-provider"]["data"][0]["id"];
}
}
var connection = new VssConnection(clientBaseAddress, new VssBasicCredential(string.Empty, pat));
var wiclient = connection.GetClient<WorkItemTrackingHttpClient>();
var workItem = wiclient.GetWorkItemAsync(projectName, Int32.Parse(workItemId)).Result;
Upvotes: 2