2

I have a IBuildDetail variable with the build information I need.

Okay, but when I check the property BuildAgent it's showing this: build.BuildAgent' threw an exception of type 'System.NotImplementedException

Then I tryed to check build.BuildController.Agents, it's nice I found the BuildAgent, but there are 7 build agents in this collection. I need only the build agent related to my build, not all build agents from that controller.

Anyone knows how to get that information? (Select a build agent name or machine name using an IBuildDetail variable)

-> I'm using TFS2010 api and I need to what is the agent for each build

Fabito
  • 1,165
  • 2
  • 13
  • 30

3 Answers3

3

When the build finishes you should be able to get the agent information from the Information (IBuildInformation) property of IBuildDetail. You can try getting the node with the following type:

http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.common.informationtypes.agentscopeactivitytracking.aspx

and fields:

http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.common.informationfields.reservedagentname.aspx

or

http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.common.informationfields.reservedagenturi.aspx

Duat Le
  • 3,586
  • 2
  • 19
  • 18
2

It's like Duat says.
In order to answer this question, I had the chance to explore this.
The following worked for a given IBuildDetail buildDetail & access to a IBuildServer buildService:

IBuildInformation buildInformation = buildDetail.Information;
IBuildInformationNode[] buildInformationNodes = buildInformation.Nodes;
string agentUri = buildInformationNodes[0].Children.Nodes[3].Fields["ReservedAgentUri"];
IBuildAgent buildAgent = buildService.GetBuildAgent(new Uri(agentUri));
Community
  • 1
  • 1
pantelif
  • 8,524
  • 2
  • 33
  • 48
  • 1
    Magic number (0, 3) are a "no-no"! Solution from the link you provided is far better - for example function GetBuildAgentName by Hamid Shahid – Andrzej Martyna Mar 18 '14 at 16:37
1

Inside the Run On Agent scope you need to have a GetBuildAgent activity that assigns the BuildAgent details to a variable of type IBuildAgent.

You can then access the properties of that variable to get access to data about the Build Agent: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuildagent.aspx

Note: The default build workflow does this already.

Dylan Smith
  • 22,069
  • 2
  • 47
  • 62
  • I'm using the TFS2010 api to access the BuildAgent info. I'm not working with wwf. This is my code: `IBuildDetail build = ..... ; build.BuildAgent ...` -> It throws an exception... – Fabito Apr 12 '11 at 21:19