addTask
Add task instance to process model
Description
adds the task specified by taskObj
= addTask(pm
,taskNameOrInstance
)taskNameOrInstance
to the process model. You
can access the task using the task object taskObj
. For more
information, see Add Tasks to Process.
This functionality requires CI/CD Automation for Simulink Check.
specifies the properties of the task using one or more taskObj
= addTask(___,Name=Value
)Name=Value
arguments.
Examples
Add Tasks to Process Model
You can use the addTask
function to create
function-based tasks directly in the process model.
Open the Process Advisor example project.
processAdvisorExampleStart
The model AHRS_Voter
opens with the Process Advisor
pane to the left of the Simulink® canvas.
In the Process Advisor pane, click the Edit process
model
button
to
open the processmodel.m
file for the project.
Replace the contents of the processmodel.m
file with this
code:
function processmodel(pm) arguments pm padv.ProcessModel end addTask(pm,"MyCustomTask",Action=@SayHello,... IterationQuery=padv.builtin.query.FindModels); end function results = SayHello(~) disp("Hello, World!"); results = padv.TaskResult; results.Values.Pass = 1; end
This code adds a task, MyCustomTask
to the process model while
specifying that the task runs the function SayHello
one time for each
model found in the project. The function SayHello
also specifies the
results returned by the task.
Input Arguments
pm
— Process for project
padv.ProcessModel
object (default)
Process for project, specified as a padv.ProcessModel
object.
Example: pm = padv.ProcessModel
taskNameOrInstance
— Name or instance of task
string | padv.Task
object
Name or instance of a task, specified as a string or padv.Task
object.
Example: "NameOfMyTask"
Example: padv.builtin.task.RunModelStandards
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: addTask(pm,"RunOnceForEachModel",IterationQuery=padv.builtin.query.FindModels)
Title
— Human readable name that appears in Process Advisor app
Name
property of task (default) | string
Human readable name that appears in the Tasks column of the
Process Advisor app, specified as a string. By default, the Process
Advisor app uses the Name
property of the task as the
Title
.
Example: "My Task"
Data Types: string
IterationQuery
— Artifacts that task iterates over
padv.Query
object | name of padv.Query
object
Artifacts that task iterates over, specified as a padv.Query
object or the name of a padv.Query
object. By default, task objects
run one time and are associated with the project. When you specify
IterationQuery
, the task runs one time for
each artifact specified by the padv.Query
. In the
Process Advisor app, the artifacts specified by
IterationQuery
appear under task title.
For example, if the IterationQuery
for a task finds three
models, Model_A
, Model_B
, and
Model_C
, the build system creates three task iterations under the
title of the task in the Tasks column.
Each of the artifacts under the task title represents a task iteration.
For examples of different IterationQuery
values:
If you have a task where the
IterationQuery
usespadv.builtin.query.FindModels
to find each of the models in the project, the build system creates a task iteration for each model.If you have a task where the
IterationQuery
usespadv.builtin.query.FindProjectFile
to find the project file, the build system creates a task iteration for the project file.If you have a task where the
IterationQuery
usespadv.builtin.query.FindTopModels
to find top models in the project, the build system creates a task iteration for each top model.
Example: IterationQuery =
padv.builtin.query.FindModels
Data Types: string
InputQueries
— Inputs to task
padv.Query
object | name of padv.Query
object | array of padv.Query
objects
Inputs to the task, specified as:
a
padv.Query
objectthe name of
padv.Query
objectan array of
padv.Query
objectsan array of names of
padv.Query
objects
By default, padv.Task
does not have inputs. When you
specify InputQueries
, the task uses the artifacts specified by
the specified query or queries as an input.
Suppose a task runs once for each model in the project and you want to provide the
models as inputs to the task. If you specify InputQueries
as the
built-in query padv.builtin.query.GetIterationArtifact
, the query
returns each artifact that the tasks iterates over, which in this example is each of
the models in the project.
Example: InputQueries =
padv.builtin.query.GetIterationArtifact
InputDependencyQuery
— Artifact dependencies for task inputs
padv.Query
object | name of padv.Query
object
Artifact dependencies for task inputs, specified as a padv.Query
object or the name of a padv.Query
object.
The build system runs the query specified by
InputDependencyQuery
to find the dependencies for the task
inputs, since those dependencies can impact if task results are up-to-date. Typically,
you specify InputDependencyQuery
as
padv.builtin.query.GetDependentArtifacts
to get the dependent
artifacts for each task input. For example, if you specify a model as an input to a
task and you specify InputDependencyQuery
as
padv.builtin.query.GetDependentArtifacts
, the build system can
find artifacts, such as data dictionaries, that the model uses.
Example: InputDependencyQuery =
padv.builtin.query.GetDependentArtifacts
Action
— Function that task runs
function handle
Function that the task runs, specified as the function handle. When you run the task, the task runs the function specified by the function handle.
For example, if you want the task to run the function
myFunction
, specify Action
as
@myFunction
.
Example: Action = @myFunction
Data Types: function_handle
RequiredIterationArtifactType
— Type of artifact
"sl_model_file"
| "m_file"
| "ma_config_file"
| "sl_test_case"
| ...
Type of artifact, specified as one or more of the values listed in this table. To specify multiple values, use an array. The build system uses the artifact type to identify and categorize the different file types and modeling constructs in your project.
Category | Artifact Type | Description |
---|---|---|
MATLAB® | "m_class" | MATLAB class |
"m_file" | MATLAB file | |
"m_func" | MATLAB function | |
"m_method" | MATLAB class method | |
"m_property" | MATLAB class property | |
Model Advisor | "ma_config_file" | Model Advisor configuration file |
"ma_justification_file" | Model Advisor justification file | |
Process Advisor | "padv_dep_artifacts" | Related artifacts that current artifact depends on |
"padv_output_file" | Process Advisor output file | |
Project | "project" | Current project file |
Requirements | "mwreq_item" | Requirement (since R2024b) |
| Requirement (for R2024a and earlier) | |
"sl_req_file" | Requirement file | |
"sl_req_table" | Requirements Table | |
Stateflow® | "sf_chart" | Stateflow chart |
"sf_graphical_fcn" | Stateflow graphical function | |
"sf_group" | Stateflow group | |
"sf_state" | Stateflow state | |
"sf_state_transition_chart" | Stateflow state transition chart | |
"sf_truth_table" | Stateflow truth table | |
Simulink | "sl_block_diagram" | Block diagram |
"sl_data_dictionary_file" | Data dictionary file | |
"sl_embedded_matlab_fcn" | MATLAB function | |
"sl_block_diagram" | Block diagram | |
"sl_library_file" | Library file | |
"sl_model_file" | Simulink model file | |
"sl_protected_model_file" | Protected Simulink model file | |
"sl_subsystem" | Subsystem | |
"sl_subsystem_file" | Subsystem file | |
System Composer™ | "zc_block_diagram" | System Composer architecture |
"zc_component" | System Composer architecture component | |
"zc_file" | System Composer architecture file | |
Tests | "harness_info_file" | Harness info file |
"sl_harness_block_diagram" | Harness block diagram | |
"sl_harness_file" | Test harness file | |
"sl_test_case" | Simulink Test™ case | |
"sl_test_case_result" | Simulink Test case result | |
"sl_test_file" | Simulink Test file | |
"sl_test_iteration" | Simulink Test iteration | |
"sl_test_iteration_result" | Simulink Test iteration result | |
"sl_test_report_file" | Simulink Test result report | |
"sl_test_result_file" | Simulink Test result file | |
"sl_test_resultset" | Simulink Test result set | |
"sl_test_seq" | Test Sequence | |
"sl_test_suite" | Simulink Test suite | |
"sl_test_suite_result" | Simulink Test suite result |
Example: "sl_model_file"
Example: ["sl_model_file "zc_file"]
Licenses
— List of licenses that task requires
string array
List of licenses that the task requires, specified as a string array.
Example: Licenses = ["matlab_report_gen"
"simulink_report_gen"]
Data Types: string
AllLicenseRequired
— Setting to require all licenses for task
true
or 1
(default) | false
or 0
Setting to require all licenses for task,
specified as a numeric or logical 1
(true
) or
0
(false
). By default,
all licenses in the Licenses
property of the task are required for the task to run. Specify 0
(false
) if the task can run without
all licenses listed in the
Licenses
property.
Example: AllLicenseRequired = false
Data Types: logical
DescriptionText
— Task description
string
Task description, specified as a string.
Example: "This task runs myScript."
Data Types: string
DescriptionCSH
— Path to task documentation
string
Path to task documentation, specified as a string.
Example: DescriptionCSH =
fullfile(pwd,"taskHelpFiles","myTaskDocumentation.pdf")
Data Types: string
Output Arguments
taskObj
— Task object
padv.Task
object
Task object, returned as a padv.Task
object.
For more information, see padv.Task
.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)