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:

  1. Cloning the remote repository and creating a feature branch

  2. Editing files and committing the changes to the local repository

  3. Pushing the committed changes to the remote repository (which triggers an automated pipeline of tasks such as compiling MEX files, packaging toolboxes, and testing on the CI platform)

  4. Analyzing the reports generated by the CI platform and fixing the errors within the pipeline

  5. Merging the remote feature branch into the master branch through a pull request (which triggers another automated pipeline of tasks on the CI platform)

  6. 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:

  1. Clone the GitHub repository and create a new feature branch.

  2. Make changes to the existing files or add new files as appropriate.

  3. 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:

  1. 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 master branch.

  2. 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:

  1. Inspect the automated pipeline results and the generated test artifacts. Make appropriate changes to your code.

  2. 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 master branch.

Continuous Integration with MathWorks Products

You can use the MATLAB testing framework to create a test suite and a test runner, and customize your test runner for continuous integration workflows with the plugin classes in the matlab.unittest.plugins package. For example, the XMLPlugin class creates a plugin that produces JUnit-style XML output, and the TAPPlugin class creates a plugin that produces a Test Anything Protocol (TAP) stream.

MATLAB integrates with Jenkins using the Jenkins plugin for MATLAB. The plugin enables you to easily run your MATLAB and Simulink tests and generate artifacts, such as JUnit-style test results, TAP test results, and Cobertura code or model coverage reports. For more information, see Jenkins Plugin for MATLAB.

Different toolboxes support continuous integration workflows. This table lists common continuous integration use cases for models and code.

ToolboxUse CaseMore Information

  • Build and test models and projects

  • Cache files for simulation and code generation

About Source Control with Projects (Simulink)

Using a Project with Git (Simulink)

Share Simulink Cache Files for Faster Simulation (Simulink)

Simulink Test™

Run test files on CI platforms and collect CI-compatible coverage using Simulink Coverage™

Continuous Integration (Simulink Test)

Simulink Check™

Use Jenkins to detect metric threshold violations in a model

Fix Metric Threshold Violations in a Continuous Integration Systems Workflow (Simulink Check)

Simulink Requirements™Summarize requirements verification results for tests run on CI platforms

Include Results from External Sources in Verification Status (Simulink Requirements)

Polyspace® Bug Finder™ Server™, Polyspace Code Prover™ Server

  • Run a Polyspace analysis on C/C++ code as part of continuous integration, for instance with Jenkins

  • Upload the analysis results (bugs, run-time errors, or coding standard violations) for review in the Polyspace Access web interface

  • Send e-mail notifications with Polyspace Bug Finder or Polyspace Code Prover results

Run Bug Finder Analysis on Server During Continuous Integration (Polyspace Bug Finder Server)

Run Code Prover Analysis on Server During Continuous Integration (Polyspace Code Prover Server)

See Also

Related Topics

External Websites