I run into a situation which needed to run a batch file from TFS Build, this batch file downloads some files from a file server and I just needed to copy that files later during the same build process to another machine.
I will simulate that by creating a batch file that create a file and copy the created file to another machine.
- Open any Build Process Template and delete all its activities.
- Add Sequence Activity with name: Overall Build Process.
- Drag and drop GetBuildDetail Activity inside the Sequence Activity.
- Drag and drop AgentScope Activity with name: Run on Agent.
- Drag and drop GetBuildDirectory Activity inside AgentScope Activity.
- Drag and drop InvokeProcess Activity with name: Call a batch file.
- Declare variable of type IBuildDetail with name: MyBuildDetail,and assign the return value from GetBuildDetail to it.
- Declare variable of type String with name: MyBuildDirectory,and assign the return value from GetBuildDirectory to it. More information on how to assign a value to variable from the return execution of activity
We need to include the folder that contains the script or the batch file in the Source Settings of our Build Definition; so the build server copy it in the working directory of the build.
But first, let’s remember what is the working directory of the build, it’s a folder like a temp folder the build process uses to get the last change set so it could build it, we configure that from TFS Administration Console for the agent.
So we will need to include the folder that contains the script or the batch file in the Source Settings of our Build Definition.
Then I will need to copy that file to the needed machine, see the following post for typical steps.