Building a MATLAB Project

What This Guide Covers #

This guide covers build environment and configuration topics specific to MATLAB® and Simulink® projects. Please make sure to read our Tutorial and general build configuration guides first.

Currently, MATLAB builds are available only for public projects in Linux® environments.

Community-Supported Language #

The MATLAB language is maintained by MathWorks®. If you have any questions or suggestions, please contact MathWorks at continuous-integration@mathworks.com.

Specify MATLAB Releases and Run Tests #

Specify MATLAB releases using the matlab key. You can specify R2020a or a later release. If you do not specify a release, Travis CI uses the latest release of MATLAB.

language: matlab
matlab:
  - latest  # Default MATLAB release on Travis CI
  - R2020a

When you include language: matlab in your .travis.yml:

  • Travis CI installs the specified MATLAB release on a Linux-based build agent. If you do not specify a release, Travis CI installs the latest release of MATLAB.
  • MATLAB runs the tests in your repository and fails the build if any of the tests fails.

If your source code is organized into files and folders within a MATLAB project, then MATLAB runs any test files in the project that have been labeled as Test. If your code does not leverage a MATLAB project, then MATLAB runs all tests in the root of your repository, including its subfolders.

You can override the default test run and generate artifacts by creating a test runner and customizing the runner with the plugin classes in the matlab.unittest.plugins package. For more information on how to specify and run MATLAB commands, see Run Custom MATLAB Commands.

Run Custom MATLAB Commands #

You can specify the script key in your .travis.yml to build on the functionality provided by language: matlab. To run custom MATLAB commands in your pipeline, use the matlab command with the -batch option. matlab -batch starts MATLAB noninteractively and runs the specified script, function, or statement. For example, call the disp function using the latest release of MATLAB.

language: matlab
script: matlab -batch 'disp("Hello World")'

If you need to specify more than one MATLAB command, use a comma or semicolon to separate the commands.

language: matlab
script: matlab -batch 'results = runtests, assertSuccess(results);'

You can write a MATLAB script or function as part of your repository and execute this script or function. For example, use MATLAB R2020a to run the commands in a file named myscript.m in the root of your repository. (To run a MATLAB script or function, do not specify the file extension.)

language: matlab
matlab: R2020a
script: matlab -batch 'myscript'

MATLAB exits with exit code 0 if the specified script, function, or statement executes successfully without error. Otherwise, MATLAB terminates with a nonzero exit code, which causes the build to fail. You can use the assert or error functions in your code to ensure that builds fail when necessary.

See Also #

Continuous Integration with MATLAB and Simulink
Continuous Integration (MATLAB)
Continuous Integration (Simulink Test)