Set Up Simulink Diff and Merge in CI/CD Pipeline
You can use Simulink® diff and merge in a continuous integration/continuous deployment (CI/CD) pipeline to track, review, and validate changes to your models.
This diagram illustrates a typical collaboration workflow. A developer makes changes locally and prequalifies the changes. To make the changes available to other contributors, the developer creates a merge request and sends the changes for review. Typically, a merge request is configured to trigger several validation steps including running tests and checking for conflicts in files. The developer addresses the feedback from reviewers, fixes test failures, if any, and resolves flagged conflicts before finalizing the merge request.
This general outline describes how to incorporate Simulink comparison and merge tools in your CI/CD pipeline.
Use a version control system such as Git™ to track your work. Commit your source files, including your Simulink models, to allow tracking changes over time.
Set up a CI pipeline using a CI/CD platform or tool such as GitHub®, GitLab®, or Jenkins® to run MATLAB® code and Simulink models as part of your automated tasks. For more information about available integrations, see Continuous Integration with MATLAB on CI Platforms.
Configure your pipeline to automatically trigger Simulink comparison regularly or for specific events. For example, you can configure your pipeline to automatically perform a comparison and generate diff reports on every merge or pull request. You can follow this pseudo-code in your pipeline.
for every SLX or MDL model in the changeset do if ancestor exists do get ancestor of model diff model to ancestor generate and save diff report if diff filters available do specify which filter to apply in the report end_if end_if end_for
For an example that provides MATLAB scripts and YAML files to generate diff reports and attach them to a GitHub pull request, see Attach Model Comparison Report to GitHub Pull Requests and watch Simulink Model Comparison for GitHub Pull Requests (4min 46sec).
Configure your pipeline to automerge models when possible. Enabling Simulink automerge ensures smoother branch merges.
If your files are under Git source control, you can use the
mlAutoMerge
Git plugin to automatically merge branches that contain changes in different subsystems, Stateflow® charts, and configuration sets in the same SLX file. For more information, see Automatically Merge Models.Tip
If you are not working in different subsystems, conflicts may occur. If a merge request flags merge conflicts, you must resolve the conflicts locally using the Three-Way Merge Tool. For an example on how to resolve conflicts, see Resolve Conflicts in Models Using Three-Way Merge.
For best practices on how to minimize the occurrence of conflicts in models, see Resolve Conflicts in Models Under Source Control.
Store the comparison report in a location that can be easily accessed and reviewed as part of the CI/CD pipeline. You can automate this process by adding a step in your pipeline to attach the diff reports. For example, you can attach the comparison report to the merge or pull request. For more information, see Attach Model Comparison Report to GitHub Pull Requests.
Implement the feedback from reviewers, validate your changes, and verify the results of any checks your pipeline is running. For example, you typically configure a merge request to trigger several validation steps, including running tests and checking for conflicted files. If a merge request flags any test failures or merge conflicts, you must fix the test failures and resolve the conflicts locally using the Three-Way Merge Tool. When you submit your fixes, the checks in your merge request run again. When all results are clean, the merge request can be accepted.
See Also
visdiff
| Comparison Tool | Three-Way Merge Tool