1

I'm currently trying to setup Jenkins to run MATLAB Tests and I have troubles getting output sometimes. I'm calling MATLAB in a pipeline via

bat '"PATH/matlab" -wait -nosplash -nodesktop -nogui -r "COMMAND"'

If COMMAND is exit(0) or exit(1) the step ends with the correct error code. However, if an error occurs e.g. if COMMAND is error(\'some error\') (or simply error) then MATLAB seems to never return. What could be the reason of this? How can I make MATLAB return with an error code to Jenkins if an error occurs?

Meera
  • 318
  • 3
  • 16
  • 1
    I believe this is because an error command in matlab reports the error to matlab, not the caller. Why do you need this? maybe there is another way – Ander Biguri May 29 '18 at 10:21
  • I want to prevent the build from getting stuck and also receive useful error information in case an error happens. Even if I wrap most stuff that happens in the called functions in try-catch and exit with an error code, errors still might happen during execution, of which I want to be informed. – Meera May 29 '18 at 10:54
  • I realized that this is not a Jenkins specific problem, but a general problem with calling matlab from the command line. I found two helpful stackoverflow questions that help me, if put together: https://stackoverflow.com/questions/9337067/how-do-i-quit-matlab-after-execution-is-finished-through-command -> By wrapping the COMMAND in a try-catch block directly in the bat command I can prevent matlab from staying stuck open. AND https://stackoverflow.com/questions/37830871/how-to-get-matlab-output-in-jenkins-console -> by using a logfile as workaround I can get output in the Jenkins console. – Meera May 29 '18 at 11:45

0 Answers0