The orb for MATLAB® on the CircleCI® Orb Registry enables you to build and test your MATLAB project as part of your pipeline. For example, you can automatically identify any code issues in your project, run tests and generate test and coverage artifacts, and package your files into a toolbox.
To use this orb, opt in to using third-party orbs in your organization security settings. You can run MATLAB on a cloud-hosted runner (executor) by invoking the orb in your CircleCI configuration file and authoring your pipeline using the orb commands as steps in jobs. You must include the install command in your jobs to install your preferred MATLAB release on the runner. For more information about cloud-hosted runners, see Execution environments overview.
When you author your pipeline in a file named .circleci/config.yml in the root of your repository, the orb provides you with four commands:
installcommand — Install a specific release of MATLAB on a cloud-hosted runner.run-buildcommand — Run a MATLAB build using the MATLAB build tool.run-testscommand — Run MATLAB and Simulink® tests and generate artifacts.run-commandcommand — Run MATLAB scripts, functions, and statements.
Using the latest release of MATLAB, run a MATLAB build task named mytask and each task it depends on. These tasks must be specified in a build file named buildfile.m in the root of your repository. To install the latest release of MATLAB on the runner, specify the install command in your pipeline. To run the MATLAB build task mytask, specify the tasks parameter of the run-build command. (The run-build command is supported in MATLAB R2022b and later.)
version: 2.1
orbs:
matlab: mathworks/matlab@1
jobs:
run-matlab-build:
machine:
image: ubuntu-2204:current
steps:
- checkout
- matlab/install
- matlab/run-build:
tasks: mytask
workflows:
build:
jobs:
- run-matlab-buildUsing the latest release of MATLAB, run the tests in your MATLAB project and generate test results in PDF and JUnit-style XML formats and code coverage results in HTML format. Upload the generated artifacts to CircleCI once the test run is complete. To install the latest release of MATLAB on the runner, specify the install command in your pipeline. To run the tests and generate the artifacts, specify the run-tests command.
version: 2.1
orbs:
matlab: mathworks/matlab@1
jobs:
run-matlab-tests:
machine:
image: ubuntu-2204:current
steps:
- checkout
- matlab/install
- matlab/run-tests:
test-results-pdf: test-results/results.pdf
test-results-junit: test-results/results.xml
code-coverage-html: code-coverage
- store_artifacts:
path: test-results/results.pdf
- store_test_results:
path: test-results/results.xml
- store_artifacts:
path: code-coverage
workflows:
test:
jobs:
- run-matlab-tests You can access the artifacts on the pipeline's Job page in the CircleCI web app:
- To view the test results in JUnit-style XML format, open the Tests tab.
- To access the PDF test report and HTML code coverage report, open the Artifacts tab.
Run your MATLAB and Simulink tests in parallel (requires Parallel Computing Toolbox™) using the latest release of the required products. To install the latest release of MATLAB, Simulink, Simulink Test™, and Parallel Computing Toolbox on the runner, specify the products parameter of the install command in your pipeline. To run the tests in parallel, specify the use-parallel parameter of the run-tests command.
version: 2.1
orbs:
matlab: mathworks/matlab@1
jobs:
run-matlab-and-simulink-tests:
machine:
image: ubuntu-2204:current
steps:
- checkout
- matlab/install:
products: >
Simulink
Simulink_Test
Parallel_Computing_Toolbox
- matlab/run-tests:
use-parallel: true
workflows:
test:
jobs:
- run-matlab-and-simulink-testsRun the commands in a file named myscript.m in the root of your repository using MATLAB R2023b. To install the specified release of MATLAB on the runner, specify the release parameter of the install command in your pipeline. To run the script, specify the run-command command.
version: 2.1
orbs:
matlab: mathworks/matlab@1
jobs:
run-matlab-script:
machine:
image: ubuntu-2204:current
steps:
- checkout
- matlab/install:
release: R2023b
- matlab/run-command:
command: myscript
workflows:
build:
jobs:
- run-matlab-scriptYou need a MATLAB batch licensing token if your project is private or if your pipeline uses transformation products, such as MATLAB Coder™ and MATLAB Compiler™. Batch licensing tokens are strings that enable MATLAB to start in noninteractive environments. You can request a token by submitting the MATLAB Batch Licensing Pilot form.
To use a MATLAB batch licensing token:
- Create a context and add an environment variable with
MLM_LICENSE_TOKENas its name and the batch licensing token as its value. For more information about contexts, see Using contexts. - Using the context in the
workflowssection of your pipeline, give jobs that include therun-build,run-tests, andrun-commandcommands access to theMLM_LICENSE_TOKENenvironment variable.
For example, use the latest release of MATLAB to run the tests in your private project. To install the latest release of MATLAB on the runner, specify the install command in your pipeline. To run the tests, specify the run-tests command. In this example, my-context is the name of the context that includes the MLM_LICENSE_TOKEN environment variable.
version: 2.1
orbs:
matlab: mathworks/matlab@1
jobs:
run-matlab-tests:
machine:
image: ubuntu-2204:current
steps:
- checkout
- matlab/install
- matlab/run-tests
workflows:
test:
jobs:
- run-matlab-tests:
context: my-contextThe install command supports the Linux®, Windows®, and macOS platforms. Use a matrix job to run a build using the MATLAB build tool on all the supported platforms. This pipeline runs the specified job three times.
version: 2.1
orbs:
matlab: mathworks/matlab@1
executors:
linux:
machine:
image: ubuntu-2204:current
windows:
resource_class: windows.medium
machine:
image: windows-server-2022-gui:current
macos:
macos:
xcode: 14.2.0
jobs:
run-matlab-build:
parameters:
os:
type: executor
executor: << parameters.os >>
steps:
- checkout
- matlab/install
- matlab/run-build:
tasks: mytask
workflows:
build:
jobs:
- run-matlab-build:
matrix:
parameters:
os: [linux, windows, macos]You can access the orb commands in the CircleCI configuration editor.
Use the install command to install MATLAB and other MathWorks® products on a cloud-hosted runner. When you specify this command as part of your pipeline, the command installs your preferred MATLAB release (R2021a or later) on a Linux, Windows, or macOS runner and prepends it to the PATH system environment variable. If you do not specify a release, the command installs the latest release of MATLAB.
The install command accepts optional parameters.
| Parameter | Description |
|---|---|
release |
(Optional) MATLAB release to install. You can specify R2021a or a later release. By default, the value of
Example: |
products |
(Optional) Products to install in addition to MATLAB, specified as a list of product names separated by spaces. You can specify For a list of supported products, open the input file for your preferred release from the For an example of how to use the Example: |
cache |
(Optional) Option to enable caching in CircleCI, specified as Example: |
no-output-timeout |
(Optional) Amount of time the command can run without producing output, specified as a numeric value suffixed with a time unit. By default, the no-output timeout is 10 minutes ( Example: |
Product licensing for your pipeline depends on your project visibility as well as the types of products the pipeline uses:
- Public project — The orb automatically licenses all products for you, except for transformation products, such as MATLAB Coder and MATLAB Compiler.
- Private project — The orb does not automatically license any products for you.
To license products that are not automatically licensed, you can request a MATLAB batch licensing token by submitting the MATLAB Batch Licensing Pilot form. Batch licensing tokens are strings that enable MATLAB to start in noninteractive environments.
To use a MATLAB batch licensing token, first store the token in a context environment variable named MLM_LICENSE_TOKEN. Then, using the context in the workflows section of your pipeline, give jobs that include the run-build, run-tests, and run-command commands access to the environment variable. For an example, see Use MATLAB Batch Licensing Token.
Note: The
installcommand automatically includes the MATLAB batch licensing executable (matlab-batch). To use a MATLAB batch licensing token in a pipeline that does not use this command, you must first download the executable and add it to the system path.
Use the run-build command to run a build using the MATLAB build tool. Starting in R2022b, you can use this command to run the MATLAB build tasks specified in a build file. By default, the run-build command looks for a build file named buildfile.m in the root of your repository. For more information about the build tool, see Overview of MATLAB Build Tool.
The run-build command accepts optional parameters.
| Parameter | Description |
|---|---|
tasks |
(Optional) MATLAB build tasks to run, specified as a list of task names separated by spaces. If a task accepts arguments, enclose them in parentheses. If you do not specify MATLAB exits with exit code 0 if the tasks run without error. Otherwise, MATLAB terminates with a nonzero exit code, which causes the command to fail. Example: |
build-options |
(Optional) MATLAB build options, specified as a list of options separated by spaces. The command supports the same options that you can pass to the Example: |
startup-options |
(Optional) MATLAB startup options, specified as a list of options separated by spaces. For more information about startup options, see Commonly Used Startup Options. Using this parameter to specify the Example: |
no-output-timeout |
(Optional) Amount of time the command can run without producing output, specified as a numeric value suffixed with a time unit. By default, the no-output timeout is 10 minutes ( Example: |
Use the run-tests command to run tests authored using the MATLAB unit testing framework or Simulink Test and generate test and coverage artifacts. By default, the command includes any files in your project that have a Test label. If your pipeline does not use a MATLAB project, or if it uses a MATLAB release before R2019a, then the command includes all tests in the root of your repository and in any of its subfolders. The command fails if any of the included tests fail.
The run-tests command accepts optional parameters.
| Parameter | Description |
|---|---|
source-folder |
(Optional) Location of the folder containing source code, specified as a path relative to the project root folder. The specified folder and its subfolders are added to the top of the MATLAB search path. If you specify Example: |
select-by-folder |
(Optional) Location of the folder containing the tests to run, specified as a path relative to the project root folder. If you specify this parameter, the command runs only the tests in the specified folder and its subfolders. You can specify multiple folders using a colon-separated or semicolon-separated list. Example: |
select-by-tag |
(Optional) Tag of the tests to run, specified as a string scalar. If you specify this parameter, the command runs only the tests with the specified tag. For more information about test tags, see Tag Unit Tests. Example: |
strict |
(Optional) Option to apply strict checks when running tests, specified as Example: |
use-parallel |
(Optional) Option to run tests in parallel, specified as Example: |
output-detail |
(Optional) Amount of event detail displayed for the test run, specified as output-detail: verbose |
logging-level |
(Optional) Maximum verbosity level for logged diagnostics included for the test run, specified as logging-level: detailed |
test-results-html |
(Optional) Location to write the test results in HTML format, specified as a folder path relative to the project root folder. Example: |
test-results-pdf |
(Optional) Location to write the test results in PDF format, specified as a file path relative to the project root folder. On macOS platforms, this parameter is supported in MATLAB R2020b and later. Example: |
test-results-junit |
(Optional) Location to write the test results in JUnit-style XML format, specified as a file path relative to the project root folder. Example: |
test-results-simulink-test |
(Optional) Location to export Simulink Test Manager results in MLDATX format, specified as a file path relative to the project root folder. This parameter requires a Simulink Test license and is supported in MATLAB R2019a and later. Example: |
code-coverage-html |
(Optional) Location to write the code coverage results in HTML format, specified as a folder path relative to the project root folder. Example: |
code-coverage-cobertura |
(Optional) Location to write the code coverage results in Cobertura XML format, specified as a file path relative to the project root folder. Example: |
model-coverage-html |
(Optional) Location to write the model coverage results in HTML format, specified as a folder path relative to the project root folder. This parameter requires a Simulink Coverage™ license and is supported in MATLAB R2018b and later. Example: |
model-coverage-cobertura |
(Optional) Location to write the model coverage results in Cobertura XML format, specified as a file path relative to the project root folder. This parameter requires a Simulink Coverage license and is supported in MATLAB R2018b and later. Example: |
startup-options |
(Optional) MATLAB startup options, specified as a list of options separated by spaces. For more information about startup options, see Commonly Used Startup Options. Using this parameter to specify the Example: |
no-output-timeout |
(Optional) Amount of time the command can run without producing output, specified as a numeric value suffixed with a time unit. By default, the no-output timeout is 10 minutes ( Example: |
Note: To customize the pretest state of the system, you can specify startup code that automatically executes before your tests run. For information on how to specify startup or shutdown files in a MATLAB project, see Automate Startup and Shutdown Tasks. If your pipeline does not use a MATLAB project, specify the commands you want executed at startup in a
startup.mfile instead, and save the file to the root of your repository. Seestartupfor more information.
Use the run-command command to run MATLAB scripts, functions, and statements. You can use this command to flexibly customize your test run or add a step in MATLAB to your pipeline.
The run-command command requires a parameter and also accepts optional parameters.
| Parameter | Description |
|---|---|
command |
(Required) Script, function, or statement to execute. If the value of 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 orb command to fail. To fail the orb command in certain conditions, use the Example: |
startup-options |
(Optional) MATLAB startup options, specified as a list of options separated by spaces. For more information about startup options, see Commonly Used Startup Options. Using this parameter to specify the Example: |
no-output-timeout |
(Optional) Amount of time the command can run without producing output, specified as a numeric value suffixed with a time unit. By default, the no-output timeout is 10 minutes ( Example: |
When you use this orb command, all of the required files must be on the MATLAB search path. If your script or function is not in the root of your repository, you can use the addpath, cd, or run function to put it on the path. For example, to run myscript.m in a folder named myfolder located in the root of the repository, you can specify command like this:
command: addpath("myfolder"), myscript
- By default, when you use the
run-build,run-tests, orrun-commandcommand, the root of your repository serves as the MATLAB startup folder. To run your MATLAB code using a different folder, specify the-sdstartup option or include thecdcommand when usingrun-command. - The
run-buildcommand uses the-batchoption to invoke the MATLAB build tool. In addition, in MATLAB R2019a and later, therun-testsandrun-commandcommands use the-batchoption to start MATLAB noninteractively. MATLAB settings do not persist across different MATLAB sessions launched with the-batchoption. To run code that requires the same settings, use a single command. - When you use the
install,run-build,run-tests, andrun-commandcommands, you execute third-party code that is licensed under separate terms.
If you encounter a product licensing issue, consider requesting a MATLAB batch licensing token to use in your pipeline. For more information, see Use MATLAB Batch Licensing Token.
If you have an enhancement request or other feedback about this orb, create an issue on the Issues page.
For support, contact MathWorks Technical Support.
