Main Content

Run Build from Toolstrip

Since R2025a

If a build file named buildfile.m is open in the MATLAB® Editor or if a project contains a build file named buildfile.m in its root folder, then you can interactively run the default tasks or a specific task in the build file from the MATLAB Toolstrip. You can also customize your build run by selecting build options from the toolstrip. For example, you can choose to continue running the build upon a failure.

This topic shows how to run a build interactively using the Editor or Project tab on the toolstrip.

Run Build in Editor

In your current folder, create a build file named buildfile.m with three tasks. Create the "check" and "test" tasks using built-in task classes, and create the "archive" task using a local task function. For more information on how to create a build file, see Create and Run Tasks Using Build Tool.

function plan = buildfile
import matlab.buildtool.tasks.CodeIssuesTask
import matlab.buildtool.tasks.TestTask

% Create a plan from task functions
plan = buildplan(localfunctions);

% Add a task to identify code issues
plan("check") = CodeIssuesTask;

% Add a task to run tests
plan("test") = TestTask;

% Make the "archive" task the default task in the plan
plan.DefaultTasks = "archive";

% Make the "archive" task dependent on the "check" and "test" tasks
plan("archive").Dependencies = ["check" "test"];
end

function archiveTask(~)
% Create ZIP file
filename = "source_" + ...
    string(datetime("now",Format="yyyyMMdd'T'HHmmss"));
zip(filename,"*")
end

When you save the build file, the Run section on the Editor tab changes to Run Build and lets you run the tasks in the build file.

Run Build section on the Editor tab

In the Run Build section, click . MATLAB displays the command it uses to run the build in the Command Window and runs the default task in the build file. The build tool first runs the "check" and "test" tasks because the "archive" task depends on them. Your results might vary, depending on the files in your current folder and its subfolders.

>> buildtool -ui
** Starting check

Analysis Summary:
    Total Files: 3
         Errors: 0 (Threshold: 0)
       Warnings: 0 (Threshold: Inf)
           Info: 0 (Threshold: Inf)
** Finished check

** Starting test
...

Test Summary:
    Total Tests: 3
         Passed: 3
         Failed: 0
     Incomplete: 0
       Duration: 0.11904 seconds testing time.
                 
** Finished test

** Starting archive
** Finished archive

Build Successful:
    3 Tasks: 0 Failed, 0 Skipped
    3.724 sec total build time

To run a specific task instead of any default tasks in the build file, open the list of tasks by clicking Run Build on the toolstrip. The list displays the task names in alphabetical order.

Menu displayed as a result of clicking Run Build. The menu has three sections. The Tasks section lists the "archive", "check", and "test" tasks. The Options section includes the Continue on Failure, Parallel, and Use Test Browser build options. The Verbosity section includes the Verbosity build option.

Note

If your build file contains task groups, then the list includes those task groups but not the tasks within them. You cannot run individual tasks in task groups from the toolstrip. For more information about task groups, see Create Groups of Similar Tasks.

Run the "test" task by selecting test under Tasks. MATLAB displays the command it uses to run the task in the Command Window and runs the "test" task.

>> buildtool test -ui
** Starting test
...

Test Summary:
    Total Tests: 3
         Passed: 3
         Failed: 0
     Incomplete: 0
       Duration: 0.037997 seconds testing time.
                 
** Finished test

Build Successful:
    1 Task: 0 Failed, 0 Skipped
    2.2513 sec total build time

Customize Build Run

You can interactively customize your build run by using the build options under Run Build. The build tool uses the selected options whether you run the default tasks or a specific task in the build file. When you select a build option, the selection persists across different MATLAB sessions.

Build OptionDescription

Continue on Failure

Continue running the build upon a build environment setup or task failure. Select this option to run the subsequent tasks upon a failure.

Selecting this option is the same as specifying the -continueOnFailure option of the buildtool command.

Parallel

Run the tasks in parallel (requires Parallel Computing Toolbox™). Select this option to run the tasks using the process-based parallel pool returned by the gcp (Parallel Computing Toolbox) function.

Selecting this option is the same as specifying the -parallel option of the buildtool command.

Use Test Browser (since R2026a)

Display the test results from matlab.buildtool.tasks.TestTask instances in the Test Browser app. To opt out of showing the test results in the test browser, clear the Use Test Browser option.

The build tool removes any tests from the test browser before running the first TestTask instance. As the tests associated with each TestTask instance run, their results appear in the Test Browser panel.

Tests associated with each TestTask instance run using the test runner constructed by that instance. If, after the build, you rerun the tests using the test browser instead of the build tool, you might get different results depending on the test browser settings.

Verbosity (since R2026a)

Control the amount of information displayed during a build run. To display build output at a specified verbosity level, click Verbosity to open a menu, and then select a value from that menu.

Selecting a value for this option is the same as specifying the -verbosity option of the buildtool command with that value.

Run Build in Project

When you open a MATLAB project, the Project tab includes the Run Build button in its Environment section.

Run Build button in the Environment section on the Project tab

If your project root folder contains a build file named buildfile.m, then you can use the button to interactively run the default tasks or a specific task in that build file.

If your project root folder does not contain a build file named buildfile.m, then you can create a starter build file from the toolstrip in two different ways:

  • Click and then click Create in the dialog box that appears.

  • Click Run Build and then select Create build file from the menu.

MATLAB creates a simple build file named buildfile.m in your project root folder and opens it in the Editor. Use this build file as a starting point for defining your build. Once your build definition is complete, you can run your build interactively from the toolstrip.

See Also

Functions

Namespaces

Topics