Get build command-line arguments?
-
Monday, July 16, 2012 4:09 PM
Hi,
We are using TFS 2008 and have encountered no problem queuing builds with command-line arguments (via directly setting IBuildRequest.ProcessParameters).
However, we cannot retrieve the command-line arguments of a queued or even a running build. IQueuedBuild.ProcessParameters returns null on us when we query for builds. May I know if there is any way to do this?
I believe there must be a way, because VS 2008 Build Explorer clearly shows the command-line arguments that we have for our builds.
Thanks!
All Replies
-
Tuesday, July 17, 2012 9:19 AMModerator
Hi atomcrusader,
Thanks for your post!
Please try to use
string processParameters = res.Builds[0].BuildDefinition.ProcessParameters;
This returns the current process parameters for the build definition.
Hope it helps!
Best Regards,
Cathy Kong [MSFT]
MSDN Community Support | Feedback to us
-
Tuesday, July 17, 2012 2:49 PM
Hi Cathy,
Thank you for replying! Just to clarify, I add command-line arguments to the builds either manually (clicking "Queue New Build..." on the build and type in the parameters in the box), or programmatically:
IBuildRequest request = buildDef.CreateBuildRequest(); request.ProcessParameters = string.Format(@"/p:shelveset=""{0}"";customoptions=true", shelveset.Name); IQueuedBuild queuedBuild = buildServer.QueueBuild(request);My test code is as follows (I am interested in getting the command-line arguments of all queued builds):
IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer)); IQueuedBuildSpec qbs = buildServer.CreateBuildQueueSpec("testTeamProject"); IQueuedBuildQueryResult result = buildServer.QueryQueuedBuilds(qbs); foreach (IQueuedBuild qb in result.QueuedBuilds) { Console.WriteLine(" Params: " + qb.BuildDefinition.ProcessParameters) ; Console.ReadLine(); }Yes, the ProcessParameters are no longer null! However, they seem to be a dictionary in XML format, but does not have the command-line argument that I add to (either manually or automatically). The dictionary only has one key: COnfigurationFolderPath, and the value.
Edit: if it's not clear, I'm trying to use VS 2010 to talk to TFS 2008. I've tried using older verision of the DLLs and GetCommandLineArguments worked perfectly, as expected. :)
- Edited by atomcrusader Tuesday, July 17, 2012 3:36 PM
- Marked As Answer by Cathy KongMicrosoft Contingent Staff, Moderator Wednesday, July 18, 2012 7:37 AM
- Unmarked As Answer by atomcrusader Friday, July 20, 2012 4:32 AM
-
Wednesday, July 18, 2012 7:37 AMModerator
Hi atomcrusader,
Thanks for sharing the experiences here!
Best Regards,
Cathy Kong [MSFT]
MSDN Community Support | Feedback to us
-
Friday, July 20, 2012 4:40 AM
Dear Cathy,
I apologize for the confusion. What I meant was that the ProcessParameters do not contain what I need -- the MSBuild's command line arguments that were passed in with the builds as they got queued. So I am still stuck on this issue...
I am exploring another path: using a DLL reference to the 2008 version of the API for Microsoft.Teamfoundation.Build.Client. I am then able to use the GetCommandlineArguments on the IBuildDetails of builds that I can obtain by means of calling ibuildServer.QueryBuilds(...). However, using this method, I can only see the builds that are already in progress or stopped... not those that are on queue. Apparently, the 2008 API does not have the QueryQueuedBuilds method for the IBuildServer interface. (If it did, I could hopefully get the IQueuedBuilds for those builds on queue, and ask their CommandlineArguments properties.)
I may be confusing something fundamental here: does a build's IBuildDetails in tfs 2008 only get created (and hence obtainable via iBuildServer.QueryBuilds()) when it's off the queue? How come I cannot see the command line arguments for builds that are on queue?
My final goal is to be able to read the MSBuild command line arguments of all builds that are either queued or in progress or postponed. Either 2008 or 2010 API is fine, as long as the job gets done.
Again, sorry for any confusion that arose from my communications. I really appreciate your help!
- Edited by atomcrusader Friday, July 20, 2012 5:44 AM Clarification of intent
-
Monday, July 23, 2012 5:24 PM
At last! I have been able to not only get all queued-not-yet-In-Progress builds, but also their command line arguments.
If you would just like to get the list of builds with your own status filter, do the following (VS2008-VS2010 API applicable):
TeamFoundationServer tfs = new TeamFoundationServer("http://server::port"); IBuildServer buildServer = tfs.GetService(typeof(buildServer)); IQueuedBuildsView queuedBuildView = buildServer.CreateQueuedBuildsView("TeamProjectName"); queuedBuildView.StatusFilter = v9TFSBuildClient.QueueStatus.InProgress | v9TFSBuildClient.QueueStatus.Queued | v9TFSBuildClient.QueueStatus.Postponed; // bitwise or the flags you want! queuedBuildView.StatusChanged += new v9TFSBuildClient.StatusChangedEventHandler(DiscoverBuilds); queuedBuildView.Connect();// <-- this will immediately call YourEventHandler. var queue = (v9TFSBuildClient.IQueuedBuildsView)sender; void DiscoverBuilds(object sender, v9TFSBuildClient.StatusChangedEventArgs e) foreach (v9TFSBuildClient.IQueuedBuild curBuild in queue.QueuedBuilds) { // do stuff here }
IF you would also like to get the command line arguments, then at //do stuff here above, you can
access the IQueuedBuild.CommandLineArguments, but only in VS 2008. I actually have to include
older DLLs to be able to do this in my otherwise VS2010 projects.
There are already lots of guide online for how to include multiple DLL versions. To keep my code clear, I use the following shortcut:
using v9TFSBuildClient = version9::Microsoft.TeamFoundation.Build.Client; using v9TFSClient = version9::Microsoft.TeamFoundation.Client;
And so, a "retro" reference to TFS 2008 server will be v9TFSClient::TeamFoundationServer //etc.
Thanks for your help!
- Marked As Answer by atomcrusader Monday, July 23, 2012 5:24 PM

