Main Content

dependsOn

Create dependency between tasks

    Description

    dependsOn(taskObj,dependencies) creates a dependency between taskObj and dependencies. taskObj runs only after the tasks specified by dependencies run and return a task status.

    This function requires CI/CD Automation for Simulink Check.

    example

    dependsOn(___,Name=Value) specifies how the build system handles dependencies using one or more Name=Value arguments.

    Note

    You can specify the relationship between two tasks as either a dependsOn relationship or a runsAfter relationship, but not both.

    If you define multiple relationships between the same tasks, the build system only uses the most recent relationship and ignores previous relationships. For example:

    dependsOn(taskA, taskB)
    dependsOn(taskB, taskA) % build system only uses this relationship

    Examples

    collapse all

    Use the dependsOn function to create a dependency between two tasks in a process model.

    Open the Process Advisor example project.

    processAdvisorExampleStart

    Open the processmodel.m file. The file is at the root of the project.

    Replace the contents of the processmodel.m file with the following code:

    function processmodel(pm)
        arguments
            pm padv.ProcessModel
        end
    
        TaskA = padv.Task("TaskA");
        TaskB = padv.Task("TaskB");
    
        dependsOn(TaskB,TaskA);
    
        addTask(pm,TaskA);
        addTask(pm,TaskB);
        
    end

    This code uses padv.Task to create two task objects: TaskA and TaskB.

    The object function dependsOn specifies that TaskB depends on TaskA.

    The function addTask adds the task objects to the padv.ProcessModel object.

    Open the Process Advisor app. In the MATLAB® Command Window, enter:

    processAdvisorWindow

    In the Tasks column, point to the run button for TaskB. The Process Advisor app automatically highlights both tasks since TaskA is a dependent task. If you click the run button for TaskB, TaskA will run before TaskB.

    TaskB depends on TaskA. Both tasks are highlighted in the Process Advisor app.

    Input Arguments

    collapse all

    Task object that represents a task, specified as a padv.Task object.

    Example: myTaskObj = padv.Task("myTask");

    Tasks that need to run before taskObj runs, specified as either:

    • The name of a task, specified as a string or character vector.

    • A padv.Task object.

    Example: dependsOn(TaskB,"TaskA")

    Example: dependsOn(TaskB,TaskA)

    Data Types: char | string

    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: dependsOn(TaskB,TaskA,WhenStatus=["Pass","Fail"])

    Setting that controls which dependent task iterations run, specified as a numeric or logical 1 (true) or 0 (false):

    • true — When the build system runs the dependencies of a task, the build system runs only the task iterations that the tasks have in common.

    • false — When the build system runs the dependencies of a task, the build system runs all task iterations. This behavior is useful when you have a task that creates new project artifacts and a task that runs on each artifact in the project. The second task depends on all project artifacts generated by the first task.

    For example, suppose you have two tasks: TaskA and TaskB:

    • TaskA runs on ModelA and ModelB.

    • TaskB runs only on ModelB and depends on TaskA.

    If you run TaskB and:

    • IterationArtifactMatching is true, TaskA runs only on ModelB.

      Mouse pointing to run button for ModelB task iteration for TaskB. The Process Advisor app only highlights the ModelB task iteration in TaskA.

    • IterationArtifactMatching is false, TaskA runs on both ModelA and ModelB.

      Mouse pointing to run button for ModelB task iteration for TaskB. The Process Advisor app highlights both the ModelA and ModelB task iterations for TaskA.

    Example: dependsOn(TaskB,TaskA,IterationArtifactMatching=false)

    Data Types: logical

    Setting that controls when dependencies run, specified as either:

    • "Pass" — Only run the task if the dependencies pass. For example, if TaskB depends on TaskA, TaskA needs to pass before TaskB runs. If TaskA fails or errors, TaskB does not run.

    • ["Pass","Fail"] — Only run the task if the dependencies either pass or fail. For example, if TaskB depends on TaskA, TaskA needs to either pass or fail before TaskB runs. If TaskA errors, TaskB does not run.

    • ["Pass","Fail","Error"] — The task runs, even if the dependencies fail or error. For example, if TaskB depends on TaskA, TaskA can pass, fail, or error and TaskB still runs.

    Example: dependsOn(TaskB,TaskA,WhenStatus=["Pass","Fail"])

    Data Types: string

    Tips

    In your process model, you can specify the relationship between tasks as either a dependsOn or runsAfter relationship. If you want to specify a preferred task execution order for tasks that do not depend on each other, you can specify your preferred task execution order by using the runsAfter method instead. For more information, see Define Task Relationships.