I recently managed to get Matlab integrated nicely(?) into TeamCity and I thought I would share my result since there isn't much on the web to help.
I am using:
Windows 7 64 bit
TeamCity Professional 9.0.1 (build 32116)
svn, version 1.8.11 (r1643975)
First things first, the build agent. Because of Matlab licensing you need to ensure the build agent service runs as the same user that Matlab is licensed for, not the system. Do this by opening the Window Services app, going to the 'properties' section of the TeamCity Build Agent service, selecting the 'Log On' tab, choose the 'This Account' option and then entering the users details. If you don't, your build will fail quickly with a licensing issue (you actually get weird popups for 'interactive services detection').
For the build I am using a build step with the 'Runner Type' set to 'Command Line'. Using a 'custom script' I have this to run my tests:
matlab -wait -r "test_gmarOvernight" -logfile %%mllogfile%%
The double % are required to escape the % for accessing dos variables.
In my test_gmarOvernight.m file I ensure that I exit the code with a 0 for a pass, and another number for a fail:
%Tests go here
% something went wrong in one or more of the tests
exit(1); %risk tests failed exit code
%something went wrong with this script
exit(2); %test script failed exit code
When I run Matlab from TeamCity I get nothing in the build log from the matlab prompt running the tests. Sending the results to a logfile, and then using 'type' in the script sends the prompt text to the build log so you can see what actually happened.
Because 'type' also sets the dos errorlevel I have to save it straight after the matlab call to another dos variable and then return it as the last step in the script.
Finally, one of my tests uses xlsread. If you get an exception like this in your Matlab log:
Microsoft Office Excel cannot access the file 'd:\testing\testing.xls'.
There are several possible reasons:
• The file name or path does not exist
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
Then there is some weird Windows automation error. This took a while to find (thanks Google for find this guys solution Author : Debarchan(MSFT) SQL Developer Engineer, Microsoft) but it worked for me:
For Windows 2008 Server x64: Create the following directory:
For Windows 2008 Server x86: Create the following directory:
I hope this helps someone else get going as I've been through a bit of pain solving all this!