Run the tasks in a plan and access the build result.
Open the example and then navigate to the run_plan_example folder, which contains a build file.
This code shows the contents of the build file.
function plan = buildfile
import matlab.buildtool.tasks.CodeIssuesTask
import matlab.buildtool.tasks.TestTask
% Create a plan from task functions
plan = buildplan(localfunctions);
% Add the "check" task to identify code issues
plan("check") = CodeIssuesTask;
% Add the "test" 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
Load the plan from the build file.
plan =
Plan with tasks:
archive - Create ZIP file
check - Identify code issues
test - Run tests
Run the default task in the plan. The build tool runs the "archive" task as well as both the tasks on which it depends. In this example, the tasks run successfully.
** 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.02063 seconds testing time.
** Finished test
** Starting archive
** Finished archive
Build Successful:
3 Tasks: 0 Failed, 0 Skipped
1.8397 sec total build time
Now, run only the "check" and "test" tasks.
** 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.01037 seconds testing time.
** Finished test
Build Successful:
2 Tasks: 0 Failed, 0 Skipped
1.4596 sec total build time
Run the default task and its dependencies, excluding the "check" task.
** Skipped check (user requested)
** Starting test
...
Test Summary:
Total Tests: 3
Passed: 3
Failed: 0
Incomplete: 0
Duration: 0.0087511 seconds testing time.
** Finished test
** Starting archive
** Finished archive
Build Successful:
3 Tasks: 0 Failed, 1 Skipped
1.1644 sec total build time
Display the most recent build result.
BuildResult with properties:
Failed: 0
Duration: 1.1644 sec
TaskResults: [1×3 matlab.buildtool.TaskResult]
Return the result for the "check" task by accessing the TaskResults property of the build result. The Skipped property of the corresponding TaskResult object indicates that the task was skipped, and the SkipReason property specifies the reason for skipping the task.
ans =
TaskResult with properties:
Name: "check"
Failed: 0
UpToDate: 0
Skipped: 1
SkipReason: UserRequested
Duration: 00:00:00