Develop and Integrate Software with Continuous Integration
Continuous integration (CI) is the practice of integrating code changes into a shared repository on a frequent basis. It improves team throughput and software quality by automating and standardizing activities such as building code, testing, and packaging. For example, each time a developer pushes new committed changes to the remote repository, the continuous integration platform can automatically run a suite of tests to ensure that the changes do not cause any conflicts in the target branch of the remote repository.
The benefits of continuous integration include:
Finding problems in software and fixing them soon after they are introduced.
Adding more features while reducing the resources required for debugging code.
Minimizing integration and deployment overheads by performing integration on a continuous basis.
Clearly communicating the state of software and the changes that have been made to it.
Continuous Integration Workflow
A typical software development workflow using continuous integration involves several steps:
Cloning the remote repository and creating a feature branch
Editing files and committing the changes to the local repository
Pushing the committed changes to the remote repository (which triggers an automated pipeline of tasks such as compiling MEX files, running tests, and packaging toolboxes on the CI platform)
Analyzing the reports generated by the CI platform and fixing the errors within the pipeline
Merging the remote feature branch into the main branch through a pull request (which triggers another automated pipeline of tasks on the CI platform)
Analyzing the reports generated by the CI platform and resolving the merge failures
This figure shows an example of the development cycle using the Jenkins® CI server and open-source source code management tools such as Git™ and GitHub®. For information on how to interface MATLAB® with Jenkins, see Run MATLAB Tests on Jenkins Server.
Phase 1: Develop and Qualify Feature in Local Repository
Develop a feature and commit your changes to the local repository:
Clone the GitHub repository and create a new feature branch.
Make changes to the existing files or add new files as appropriate.
Run MATLAB and Simulink® tests to qualify the changes and commit them to the local repository.
Phase 2: Run Automated Pipeline on Continuous Integration Platform
Run an automated pipeline of tasks (including testing) when you push your changes to the remote repository or when you make a pull request:
Trigger an automated pipeline of tasks on Jenkins by pushing the committed changes to GitHub or by making a pull request to merge the remote feature branch into the main branch.
Jenkins runs the automated pipeline, including MATLAB and Simulink tests, and generates artifacts as specified in the project configuration.
Phase 3: Investigate and Resolve Failures
If you do not succeed in pushing your changes or making a pull request, follow these steps:
Inspect the automated pipeline results and the generated test artifacts. Make appropriate changes to your code.
Trigger a new pipeline on Jenkins by pushing your changes to GitHub or by making a pull request.
Integration engineers can use Jenkins test artifacts to decide when to merge the feature branch into the main branch.
Continuous Integration with MathWorks Products
You can perform continuous integration with MATLAB on various continuous integration platforms. You can run and test your MATLAB code and Simulink models, generate artifacts, and publish your results to the platforms. For more information, see Continuous Integration with MATLAB on CI Platforms.
In addition to MATLAB, different toolboxes support continuous integration workflows. This table lists common continuous integration use cases for models and code.
|Toolbox||Use Case||More Information|
About Source Control with Projects (Simulink)
Using a Project with Git (Simulink)
Run test files on CI platforms and collect CI-compatible coverage using Simulink Coverage™
Continuous Integration (Simulink Test)
Use Jenkins to detect metric threshold violations in a model
|Requirements Toolbox™||Summarize requirements verification results for tests run on CI platforms|
Include Results from External Sources in Verification Status (Requirements Toolbox)
|Polyspace® Bug Finder™ Server™, Polyspace Code Prover™ Server|
Set Up Bug Finder Analysis on Servers During Continuous Integration (Polyspace Bug Finder)
Set Up Code Prover Analysis on Servers During Continuous Integration (Polyspace Code Prover)
- Set Up Git Source Control
- Use Source Control with Projects
- Explore an Example Project
- Continuous Integration with MATLAB on CI Platforms