Skip to content

Instantly share code, notes, and snippets.

@JogoShugh
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JogoShugh/8981912 to your computer and use it in GitHub Desktop.
Save JogoShugh/8981912 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-16"?>
<BuildCompletionEvent2 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<BuildUri>vstfs:///Build/Build/103</BuildUri>
<TeamFoundationServerUrl>http://tfs201064:8080/tfs/DefaultCollection</TeamFoundationServerUrl>
<Url>http://tfs201064:8080/tfs/web/build.aspx?pcguid=774086bc-c49c-4e0d-860c-98dabdf8523f&amp;builduri=vstfs:///Build/Build/103</Url>
<Title>Hello World Build Call Center_20140213.6 succeeded</Title>
<TeamProject>Hello World</TeamProject>
<AgentPath>TFS201064 - Controller</AgentPath>
<DefinitionPath>\Hello World\Call Center</DefinitionPath>
<BuildNumber>Call Center_20140213.6</BuildNumber>
<StartTime>2/13/2014 2:18:13 PM</StartTime>
<FinishTime>2/13/2014 2:18:32 PM</FinishTime>
<SourceGetVersion>C137</SourceGetVersion>
<Status>Successfully Completed</Status>
<StatusCode>Succeeded</StatusCode>
<CompilationStatus>Succeeded</CompilationStatus>
<TestStatus>Succeeded</TestStatus>
<LogLocation>\\TFS201064\TFSBuildDropLocation\Call Center\Call Center_20140213.6\logs\HelloTFS.log</LogLocation>
<DropLocation>\\TFS201064\TFSBuildDropLocation\Call Center\Call Center_20140213.6</DropLocation>
<RequestedFor>CORP\jgough</RequestedFor>
<RequestedBy>NT AUTHORITY\NETWORK SERVICE</RequestedBy>
<KeepForever>false</KeepForever>
<TimeZone>Eastern Standard Time</TimeZone>
<TimeZoneOffset>-05:00:00</TimeZoneOffset>
<Subscriber>[DefaultCollection]\Project Collection Service Accounts</Subscriber>
</BuildCompletionEvent2>
{
"ref": "refs\/heads\/master",
"after": "82bdd54186549533e948d02b84cadc96d2069ec3",
"before": "d77f04db6e30d8d003f82e22bf8313ff3cae8124",
"created": false,
"deleted": false,
"forced": false,
"compare": "https:\/\/github.com\/JogoShugh\/Test\/compare\/d77f04db6e30...82bdd5418654",
"commits": [
{
"id": "82bdd54186549533e948d02b84cadc96d2069ec3",
"distinct": true,
"message": "Update iNeedSleep.cs",
"timestamp": "2014-02-17T10:14:38-08:00",
"url": "https:\/\/github.com\/JogoShugh\/Test\/commit\/82bdd54186549533e948d02b84cadc96d2069ec3",
"author": {
"name": "Josh Gough",
"email": "jsgough@gmail.com",
"username": "JogoShugh"
},
"committer": {
"name": "Josh Gough",
"email": "jsgough@gmail.com",
"username": "JogoShugh"
},
"added": [
],
"removed": [
],
"modified": [
"iNeedSleep.cs"
]
}
],
"head_commit": {
"id": "82bdd54186549533e948d02b84cadc96d2069ec3",
"distinct": true,
"message": "Update iNeedSleep.cs",
"timestamp": "2014-02-17T10:14:38-08:00",
"url": "https:\/\/github.com\/JogoShugh\/Test\/commit\/82bdd54186549533e948d02b84cadc96d2069ec3",
"author": {
"name": "Josh Gough",
"email": "jsgough@gmail.com",
"username": "JogoShugh"
},
"committer": {
"name": "Josh Gough",
"email": "jsgough@gmail.com",
"username": "JogoShugh"
},
"added": [
],
"removed": [
],
"modified": [
"iNeedSleep.cs"
]
},
"repository": {
"id": 5422086,
"name": "Test",
"url": "https:\/\/github.com\/JogoShugh\/Test",
"description": "Test",
"watchers": 0,
"stargazers": 0,
"forks": 1,
"fork": true,
"size": 191,
"owner": {
"name": "JogoShugh",
"email": "jsgough@gmail.com"
},
"private": false,
"open_issues": 0,
"has_issues": false,
"has_downloads": true,
"has_wiki": true,
"language": "C#",
"created_at": 1345005520,
"pushed_at": 1392660879,
"master_branch": "master"
},
"pusher": {
"name": "JogoShugh",
"email": "jsgough@gmail.com"
}
}
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<EventSubscriptionsByClassificationResponse xmlns="http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Events/03">
<EventSubscriptionsByClassificationResult>
<Subscription>
<Subscriber>S-1-9-1551374245-1204400969-2402986413-2179408616-0-0-0-0-2</Subscriber>
<EventType>CheckinEvent</EventType>
<ID>90</ID>
<DeliveryPreference>
<Type>Soap</Type>
<Schedule>Immediate</Schedule>
<Address>http://jgough.corp.versionone.net:9090/service.svc</Address>
</DeliveryPreference>
<ConditionString/>
<Tag>VersionOneTFSServer</Tag>
</Subscription>
<Subscription>
<Subscriber>S-1-9-1551374245-1204400969-2402986413-2179408616-0-0-0-0-2</Subscriber>
<EventType>BuildCompletionEvent2</EventType>
<ID>91</ID>
<DeliveryPreference>
<Type>Soap</Type>
<Schedule>Immediate</Schedule>
<Address>http://jgough.corp.versionone.net:9090/service.svc</Address>
</DeliveryPreference>
<ConditionString/>
<Tag>VersionOneTFSServer</Tag>
</Subscription>
</EventSubscriptionsByClassificationResult>
</EventSubscriptionsByClassificationResponse>
</soap:Body>
</soap:Envelope>
<CheckinEvent xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AllChangesIncluded>true</AllChangesIncluded>
<Subscriber>[DefaultCollection]\Project Collection Service Accounts</Subscriber>
<CheckinNotes>
<CheckinNote xsi:type="NameValuePair" name="Code Reviewer" val="" />
<CheckinNote xsi:type="NameValuePair" name="Performance Reviewer" val="" />
<CheckinNote xsi:type="NameValuePair" name="Security Reviewer" val="" />
</CheckinNotes>
<CheckinInformation />
<Artifacts>
<Artifact xsi:type="ClientArtifact" ArtifactType="Changeset" ServerItem="">
<Url>http://tfs201064:8080/tfs/web/cs.aspx?pcguid=774086bc-c49c-4e0d-860c-98dabdf8523f&amp;cs=129</Url>
</Artifact>
<Artifact xsi:type="ClientArtifact" ArtifactType="VersionedItem" Item="Program.cs" Folder="$/Hello World/HelloTFS/HelloTFS" TeamProject="Hello World" ItemRevision="129" ChangeType="edit" ServerItem="$/Hello World/HelloTFS/HelloTFS/Program.cs">
<Url>http://tfs201064:8080/tfs/web/diff.aspx?pcguid=774086bc-c49c-4e0d-860c-98dabdf8523f&amp;opath=%24%2fHello+World%2fHelloTFS%2fHelloTFS%2fProgram.cs&amp;ocs=128&amp;mpath=%24%2fHello+World%2fHelloTFS%2fHelloTFS%2fProgram.cs&amp;mcs=129</Url>
</Artifact>
</Artifacts>
<Owner>CORP\jgough</Owner>
<CreationDate>2/12/2014 12:31:37 PM</CreationDate>
<Comment>Yep B-05747</Comment>
<TimeZone>Eastern Standard Time</TimeZone>
<TimeZoneOffset>-05:00:00</TimeZoneOffset>
<TeamProject>Hello World</TeamProject>
<PolicyOverrideComment />
<PolicyFailures />
<Title>Hello World Changeset 129: Yep B-05747</Title>
<ContentTitle>Changeset 129: Yep B-05747</ContentTitle>
<Committer>CORP\jgough</Committer>
<Number>129</Number>
</CheckinEvent>
OnBuildCompletionEvent:
Given this incoming message from TFS:
<BuildCompletionEvent2 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<BuildUri>vstfs:///Build/Build/103</BuildUri>
<TeamFoundationServerUrl>http://tfs201064:8080/tfs/DefaultCollection</TeamFoundationServerUrl>
<Url>http://tfs201064:8080/tfs/web/build.aspx?pcguid=774086bc-c49c-4e0d-860c-98dabdf8523f&amp;builduri=vstfs:///Build/Build/103</Url>
<Title>Hello World Build Call Center_20140213.6 succeeded</Title>
<TeamProject>Hello World</TeamProject>
<AgentPath>TFS201064 - Controller</AgentPath>
<DefinitionPath>\Hello World\Call Center</DefinitionPath>
<BuildNumber>Call Center_20140213.6</BuildNumber>
<StartTime>2/13/2014 2:18:13 PM</StartTime>
<FinishTime>2/13/2014 2:18:32 PM</FinishTime>
<SourceGetVersion>C137</SourceGetVersion>
<Status>Successfully Completed</Status>
<StatusCode>Succeeded</StatusCode>
<CompilationStatus>Succeeded</CompilationStatus>
<TestStatus>Succeeded</TestStatus>
<LogLocation>\\TFS201064\TFSBuildDropLocation\Call Center\Call Center_20140213.6\logs\HelloTFS.log</LogLocation>
<DropLocation>\\TFS201064\TFSBuildDropLocation\Call Center\Call Center_20140213.6</DropLocation>
<RequestedFor>CORP\jgough</RequestedFor>
<RequestedBy>NT AUTHORITY\NETWORK SERVICE</RequestedBy>
<KeepForever>false</KeepForever>
<TimeZone>Eastern Standard Time</TimeZone>
<TimeZoneOffset>-05:00:00</TimeZoneOffset>
<Subscriber>[DefaultCollection]\Project Collection Service Accounts</Subscriber>
</BuildCompletionEvent2>
Listener responds by:
- Connecting to the sender TFS by pulling out the Uri from <BuildUri>vstfs:///Build/Build/103</BuildUri>
- Getting associated changesets directly from TFS
- Looking for build projects in V1 by extracting "Call Center" out of <DefinitionPath>\Hello World\Call Center</DefinitionPath>
- If there's a corresponding Build Project in V1, then:
- Create a new BuildRun in V1
- Now, for each ChangeSetData that came FROM TFS:
- Get a corresponding V1 ChangeSet via the TFS-provided ChangesetId
- For each of these V1 ChangeSet items:
- Append the description from the TFS changeset into the existing V1 ChangeSet
- Get each build
foreach (var csd in changeSetsData)
{
var changeSets = v1Component.Value.GetChangeSets("TFS:" + csd.ChangesetId);
foreach (var changeSet in changeSets)
{
if(descriptionBuilder.Length > 0)
{
descriptionBuilder.Append(Environment.NewLine);
}
descriptionBuilder.Append(changeSet.Description);
foreach (var primaryWorkitem in v1Component.Value.GetPrimaryWorkitems(changeSet))
{
var remove = v1Component.Value.GetBuildRuns(primaryWorkitem, buildProject);
v1Component.Value.RemoveBuildRunsFromWorkitem(primaryWorkitem, remove);
v1Component.Value.Save(primaryWorkitem);
v1Component.Value.AddBuildRunsToWorkitem(primaryWorkitem, new[]{buildRun});
v1Component.Value.Save(primaryWorkitem);
}
}
v1Component.Value.AddChangeSetsToBuildRun(buildRun, changeSets);
v1Component.Value.Save(buildRun);
}
buildRun.Description = descriptionBuilder.ToString();
v1Component.Value.Save(buildRun);
Detailed code:
private void OnBuildCompletionEvent(BuildCompletionEvent2 e)
{
Debug.instance().Write("Process Build Number " + e.BuildNumber + " from " + e.TeamProject);
var tfs = Utils.ConnectToTfs();
var buildStore = (IBuildServer) tfs.GetService(typeof(IBuildServer));
var url = new Uri(e.Url);
var buildUri = HttpUtility.ParseQueryString(url.Query).Get("builduri");
var detail = buildStore.GetBuild(new Uri(buildUri));
detail.RefreshAllDetails();
var changeSetsData = InformationNodeConverters.GetAssociatedChangesets(detail);
Debug.instance().Write("Number of ChangeSets: " + changeSetsData.Count);
var reference = e.DefinitionPath;
var index = reference.LastIndexOf("\\");
if(index >= 0)
{
reference = reference.Substring(index + 1);
}
var results = v1Component.Value.GetBuildProjects(reference);
if(results.Count == 0)
{
Debug.instance().Write("No results for reference " + reference);
}
foreach (var buildProject in results)
{
var ts = DateTime.Parse(e.FinishTime, CultureInfo.InvariantCulture) - DateTime.Parse(e.StartTime, CultureInfo.InvariantCulture);
var buildRun = v1Component.Value.CreateBuildRun(buildProject, e.BuildNumber, DateTime.Parse(e.FinishTime, CultureInfo.InvariantCulture), ts.Seconds);
var statuses = v1Component.Value.GetBuildRunStatuses();
var status = e.StatusCode == "Succeeded"
? statuses.First(x => x.Name == "Passed")
: statuses.First(x => x.Name == "Failed");
buildRun.Status = status;
v1Component.Value.CreateLink(new Link(e.Url, "TFS Build Results", true), buildRun);
var descriptionBuilder = new StringBuilder();
foreach (var csd in changeSetsData)
{
var changeSets = v1Component.Value.GetChangeSets("TFS:" + csd.ChangesetId);
foreach (var changeSet in changeSets)
{
if(descriptionBuilder.Length > 0)
{
descriptionBuilder.Append(Environment.NewLine);
}
descriptionBuilder.Append(changeSet.Description);
foreach (var primaryWorkitem in v1Component.Value.GetPrimaryWorkitems(changeSet))
{
var remove = v1Component.Value.GetBuildRuns(primaryWorkitem, buildProject);
v1Component.Value.RemoveBuildRunsFromWorkitem(primaryWorkitem, remove);
v1Component.Value.Save(primaryWorkitem);
v1Component.Value.AddBuildRunsToWorkitem(primaryWorkitem, new[]{buildRun});
v1Component.Value.Save(primaryWorkitem);
}
}
v1Component.Value.AddChangeSetsToBuildRun(buildRun, changeSets);
v1Component.Value.Save(buildRun);
}
buildRun.Description = descriptionBuilder.ToString();
v1Component.Value.Save(buildRun);
}
Debug.instance().Write("BuildRun Save Successful");
}
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<wsa:To>http://jgough.corp.versionone.net:9090/service.svc</wsa:To>
<wsa:Action>http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify</wsa:Action>
</soap:Header>
<soap:Body>
<Notify>
<eventXml>&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;BuildCompletionEvent2 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt;BuildUri&gt;vstfs:///Build/Build/103&lt;/BuildUri&gt;&lt;TeamFoundationServerUrl&gt;http://tfs201064:8080/tfs/DefaultCollection&lt;/TeamFoundationServerUrl&gt;&lt;Url&gt;http://tfs201064:8080/tfs/web/build.aspx?pcguid=774086bc-c49c-4e0d-860c-98dabdf8523f&amp;amp;builduri=vstfs:///Build/Build/103&lt;/Url&gt;&lt;Title&gt;Hello World Build Call Center_20140213.6 succeeded&lt;/Title&gt;&lt;TeamProject&gt;Hello World&lt;/TeamProject&gt;&lt;AgentPath&gt;TFS201064 - Controller&lt;/AgentPath&gt;&lt;DefinitionPath&gt;\Hello World\Call Center&lt;/DefinitionPath&gt;&lt;BuildNumber&gt;Call Center_20140213.6&lt;/BuildNumber&gt;&lt;StartTime&gt;2/13/2014 2:18:13 PM&lt;/StartTime&gt;&lt;FinishTime&gt;2/13/2014 2:18:32 PM&lt;/FinishTime&gt;&lt;SourceGetVersion&gt;C137&lt;/SourceGetVersion&gt;&lt;Status&gt;Successfully Completed&lt;/Status&gt;&lt;StatusCode&gt;Succeeded&lt;/StatusCode&gt;&lt;CompilationStatus&gt;Succeeded&lt;/CompilationStatus&gt;&lt;TestStatus&gt;Succeeded&lt;/TestStatus&gt;&lt;LogLocation&gt;\\TFS201064\TFSBuildDropLocation\Call Center\Call Center_20140213.6\logs\HelloTFS.log&lt;/LogLocation&gt;&lt;DropLocation&gt;\\TFS201064\TFSBuildDropLocation\Call Center\Call Center_20140213.6&lt;/DropLocation&gt;&lt;RequestedFor&gt;CORP\jgough&lt;/RequestedFor&gt;&lt;RequestedBy&gt;NT AUTHORITY\NETWORK SERVICE&lt;/RequestedBy&gt;&lt;KeepForever&gt;false&lt;/KeepForever&gt;&lt;TimeZone&gt;Eastern Standard Time&lt;/TimeZone&gt;&lt;TimeZoneOffset&gt;-05:00:00&lt;/TimeZoneOffset&gt;&lt;Subscriber&gt;[DefaultCollection]\Project Collection Service Accounts&lt;/Subscriber&gt;&lt;/BuildCompletionEvent2&gt;</eventXml>
<tfsIdentityXml>&lt;TeamFoundationServer url="http://tfs201064:8080/tfs/DefaultCollection/Services/v3.0/LocationService.asmx" /&gt;</tfsIdentityXml>
<SubscriptionInfo>
<Classification>VersionOneTFSServer</Classification>
<ID>111</ID>
<Subscriber>S-1-9-1551374245-1204400969-2402986413-2179408616-0-0-0-0-2</Subscriber>
</SubscriptionInfo>
</Notify>
</soap:Body>
</soap:Envelope>
POST /service.svc HTTP/1.1
User-Agent: Team Foundation (TfsJobAgent.exe, 10.0.40219.1)
X-TFS-Version: 1.0.0.0
X-TFS-Session: 00000000-0000-0000-0000-000000000000
accept-language: en-US
TF-Instance: 00000000-0000-0000-0000-000000000000
SOAPAction: http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify
Content-Type: application/soap+xml; charset=utf-8
Host: jgough.corp.versionone.net:9090
Content-Length: 2743
Expect: 100-continue
Accept-Encoding: gzip
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/IService/NotifyResponse</a:Action>
<ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="a327823b-29e7-4917-aadc-6156233bd58a">25399201-d118-4a1b-bfcb-cf720920779e</ActivityId>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<NotifyResponse xmlns="http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03"/>
</s:Body>
</s:Envelope>
HTTP/1.1 200 OK
Content-Length: 687
Content-Type: application/soap+xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Thu, 13 Feb 2014 19:26:49 GMT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment