An MSDN article - How to: Configure and Run Scheduled Tests After Building Your Application – describes the steps required to run Coded UI Test as part of building the application.
For running the Coded UI test with the Build agent service, it is required to install the Test agent (or Visual Studio 2010 Premium/Ultimate) on the Build agent machine. Some of the components required for running Coded UI Tests are only available in Test Agent (or Visual Studio 2010 Premium/Ultimate).
NOTE: You can build (compile) the Coded UI Test if only Build agent is installed on the box. But you cannot run Coded UI Test on such a box.