Context provided when task runs
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.
matlab.buildtool.TaskContext class is a
Task — Copy of task being run
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.
Plan — Copy of plan being run
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.
Create Task That Uses Context
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
"test" task. In this example, all the tests pass.
** 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
Introduced in R2022b