Main Content

matlab.buildtool.TaskContext class

Package: matlab.buildtool

Context provided when task runs

Description

The matlab.buildtool.TaskContext class provides context-specific information to task actions. When the build runner runs a task, it creates a TaskContext object that contains information about the task as well as the plan being run. Actions of the running task have access to this information.

The build runner instantiates this class. You cannot create an object of the class directly.

The matlab.buildtool.TaskContext class is a handle class.

Properties

expand all

Copy of the task being run by the build runner, returned as a matlab.buildtool.Task object. This object provides access to properties of the task being run. Modifying the object does not affect the original task.

Attributes:

GetAccess
public
SetAccess
immutable

Copy of the plan being run by the build runner, returned as a matlab.buildtool.Plan object. This object provides access to properties of the plan being run. Modifying the object does not affect the original plan.

Attributes:

GetAccess
public
SetAccess
immutable

Examples

collapse all

Create a task that uses the context provided by the build runner to specify the full path to a file or folder. The full paths are for illustration purposes only. You can simplify the build file by specifying paths relative to the plan root folder.

Open the example and then navigate to the task_context_example folder, which contains a build file.

openExample("matlab/CreateTaskThatUsesContextExample")
cd task_context_example

This code shows the contents of the build file.

function plan = buildfile
plan = buildplan(localfunctions);
end
      
function testTask(context)
% Run unit tests
testFolder = context.Plan.RootFolder;     
results = runtests(testFolder,OutputDetail="terse");
generateHTMLReport(results,fullfile(testFolder,"artifacts"))
assertSuccess(results);

% Or, more simply, use paths relative to the plan root folder
% results = runtests(OutputDetail="terse");
% generateHTMLReport(results,"artifacts")  
% assertSuccess(results);
end

Run the "test" task. In this example, all the tests pass.

buildtool test
** Starting test
...
Generating test report. Please wait.
    Preparing content for the test report.
    Adding content to the test report.
    Writing test report to file.
Test report has been saved to:
 C:\task_context_example\artifacts\index.html
** Finished test

Version History

Introduced in R2022b