You need to add -wait
to the MATLAB command.
On Windows, Jenkins wraps the command in a batch file that returns immediately, and therefore doesn't capture the output (and by the way, it will also always exit with a success status even if MATLAB itself didn't).
By adding -wait
, it will delay the exit until MATLAB has finished, and it will also return with the appropriate exit status.
PS Also see this excellent series of posts by @AndyCampbell on integrating MATLAB with Jenkins.
Edit:
The above works for me. But here's a couple of other things I would check, as they've been gotchas for me when I was getting it set up - perhaps they will help you too:
- Make sure the build step is an "Execute Windows batch command" step rather than an "Execute shell" step, as it's a pain to get the unix utilities installed and running on Windows
- Make sure that you have the right type of quote marks in the MATLAB build command. They need to be straight quotes, not curly quotes - both the single and double ones
- If you copied and pasted the MATLAB build command into Jenkins, make sure you didn't accidentally paste in any extra invisible characters - try typing the command directly into Jenkins
- Make sure there are no licensing issues - for example, Jenkins may be running as
user1
and will call MATLAB as user1
, but MATLAB is licensed to user2
. If you call MATLAB with -nodesktop
in this case it will just silently fail (and may even leave a zombie MATLAB process hanging around, with an invisible license error dialog, that you can only quit from with Task Manager)
- To assist in troubleshooting, you can add
-logfile \path\to\logfile.txt
to your MATLAB command, which can diagnose some issues. You can also use a startup.m
file and/or a finish.m
file - these should run at startup (before your build command) and just before exit (after your build command). Finally you could try using a build command that does something simple to the filesystem, rather than a disp
(this would diagnose whether it's an issue with MATLAB running at all, or an issue with Jenkins collecting its output).