주요 콘텐츠

Continuous Integration for Code Generation

R2026b

You can use continuous integration/continuous deployment (CI/CD) to manage the process of incorporating model and generated code changes in a shared central repository. The CI pipeline, along with workflow tools such as Simulink® projects, can help you standardize the development and testing of Simulink models and generated code as your projects and teams scale up. For large systems, you can configure the pipeline to more efficiently build generated code by using Simulink cache files and parallel builds.

Set Up CI/CD Pipeline for Simulink

To track your work and a CI pipeline to run MATLAB® code and Simulink models, use a version control system. Commit your source files, including your Simulink models, to allow tracking changes over time. For more information about available integrations, see Continuous Integration with MATLAB on CI Platforms.

Integrate Code Generation in Pipeline

Generate Code by Calling slbuild

To generate code in the pipeline, call the slbuild function for the model.

slbuild(model);

Schedule Code Generation

Configure your pipeline to automatically trigger code generation for Simulink models regularly or for specific events such as when a model is changed or when external source code is changed. For example, you can configure your pipeline to automatically compare and merge versions of a model when the model is included in a pull request. For more information, see Set Up Simulink Diff and Merge in CI/CD Pipeline.

Speed Up Code Generation

If your pipeline must support large systems or many models, you can optionally use these methods to improve build efficiency:

Manage Code Generation Artifacts

Typically, you do not check in generated code as a source file. Source-controlled artifacts are Simulink models, data files, and nongenerated source code that integrates with the generated code. The pipeline generates the code as an artifact that you can then review and deploy.

Prequalify Artifacts Locally

While the pipeline runs model simulations and generates code, developers can perform these steps locally to prequalify their changes. For example, after changing a model, a developer can generate code locally to see the result of the change. Developers can also compare locally generated code to the generated code from the pipeline. However, if the development computer is different from the pipeline platform, the code can have platform-specific differences. For more information, see Code Generation Differences Across Platforms.

Package Code in Pipeline

When the pipeline runs slbuild for a model, the coder generates code files and places them in the folders model_grt_rtw and slprj/grt/_sharedutils.

You can optionally configure the pipeline to package the generated code, along with build information and CMake configuration files, in a ZIP file (model.zip) by calling packNGo for the generated build folder model_grt_rtw.

buildFolder = RTW.getBuildDir(model).BuildDirectory;
packNGo(buildFolder);
You can configure your pipeline to run tests on these generated code files when code is regenerated. If you have Simulink Test™, you can create model tests that are compatible with CI systems, as described in Output Results for Continuous Integration Systems (Simulink Test).

Generate Reports in Pipeline

Facilitate the review of merge requests by configuring the pipeline to generate and store report artifacts, such as the model comparison report or code generation report, in a location that reviewers can easily access. For example, see Attach Model Comparison Report to GitHub Pull Requests and Configure and Generate Code Generation Report Programmatically.

Standardize Workflow for Users

If your pipeline must support many users, you can automate the setup of source files in the pipeline.

Set Up Simulink Projects

Standardize the structure and file management of models and generated code by providing a Simulink project template from which developers can create new projects. For example, you can configure the template to use a standard folder structure and include scripts that the pipeline can use for simulating models, generating code, and generating reports. For more information, see Create Templates for Standard Project Settings.

Automate Pipeline Builds

Define a standard process for your team and CI pipeline by using the CI/CD Automation for Simulink Check support package and the Process Advisor (Simulink Check). You can automate pipeline setup, including code generation configuration, by using process advisor tasks such as the padv.builtin.task.GenerateCode (Simulink Check) task. Tasks enable you to easily configure and control steps of your pipeline build process. For more information, see Overview of Process Model (Simulink Check).

See Also

| | (Simulink Check) | (Parallel Computing Toolbox)

Topics