TFS Build Invoke Process Activity

Likely the most useful tool in the list of Team Foundation Build Activities is InvokeProcess. This little Activity lets you call out to anything you want. I have found it very useful for executing a batch file that is stored with my source code to do a number of things. Invoke a PowerGen build for PowerBuilder Applications. Invoke Devenv.exe for building Reporting Services, or calling a deployment script you don’t want to rewrite at the moment.  

When I went to use this activity the first time there was not much out there as an example so I thought I would post a quick and dirty example of using the Invoke process.

Find the place in your process where you want to make the call and drag in an InvokeProcess Activity.

Next you want messages that come from the application you are calling to end up in your Build report. This is done via stdout and stderr. So drag over a WriteBuildMessage Activity and a WriteBuildError Activity into the Invoke process as seen below.

There are two variables defined stdOutput and errOutput they need to be placed in the message property of the Write Activities. I would set the Importance property on the WriteBuildMessage Activity to High. Like this:

Now for the properties of the Invoke process. It’s pretty simple really.

DisplayName: This will be exposed in the Workflow so it’s good to name it something that reads well and tells the reader what you are doing here. 

FileName: The file you want to call. For batch files I find it useful to put the file in source control with the app. Then use the SourcesDirectory variable to find it. See Below.

Arguments: What you want to pass to the called application or batch file.

Result: Your ExitCode variable. The last thing you call from the batch file or the app will generally return an exit code then you can use that to determine if you want to carry on in the build process.

EnvironmentVariables: This dictionary of <string, string> allows you to specify environment variables and their values.

OutputEncoding: You can specify the encoding that is used to read the output (StandardOutputEncoding) and error (RedirectStandardError) streams. I have only ever used the default value.

So if I wanted to call a batch file named MyBatchFile.bat and it was in source control at the root of my solution folder, and I want to pass in the Drop Location from my build definition. My InvokeProcess might look like this.

Comments (2) -

murty
murty
12/27/2012 10:30:52 AM #

is there a way we can tell tfs to pick the batch file from tfs server rather than local server path. meaning not c:\mybatchfile.bat but $/tfsserver/mybatchfile.bat

murty
murty
12/27/2012 10:30:52 AM #

is there a way we can tell tfs to pick the batch file from tfs server rather than local server path. meaning not c:\mybatchfile.bat but $/tfsserver/mybatchfile.bat

Pingbacks and trackbacks (4)+