Typically, a sample time mismatch error in a CI pipeline can be traced back to two main causes:
1) Hard-Coded Sample Times in Referenced Models: Often, the harness models that encounter errors have their inports/outports sample times hard-coded within the referenced models. This rigidity can lead to mismatches when the build environment differs from the development environment.
2) Discrepancies Between Model Versions: A mismatch between the version of the model on a developer's personal machine and the version on the Jenkins machine can also cause these errors. Such inconsistencies can lead to unforeseen issues during the integration and build process.
Strategies for Mitigation
To circumvent the first issue, it is essential to ensure that sample times within the referenced models are defined as variables. This approach allows for greater flexibility, enabling easy adjustments to align with the configurations of various machines.
Moreover, the issue of hard-coded sample times is further complicated when dealing with harness models that utilize Model Variants with Variant activation times set at startup. This specific configuration may obscure sample time mismatch errors during local development, only for them to become evident when moved to a Jenkins environment.
If the sample times aren’t hard coded and the issue remains, here are some things you can try to make sure the there are no discrepancies between the model on your personal machine and on the Jenkins Machine:
1) Identify the Execution Mechanism:
- Determine the method used to execute your MATLAB script within the Jenkins environment. Common methods include using the command line options matlab -batch or matlab-batch, employing the MATLAB Jenkins plugin, or other execution techniques. Identifying the exact mechanism is crucial for pinpointing the root cause of the issue.
2) Replicate the Jenkins Environment:
- Even if the issue does not occur outside of Jenkins, attempt to replicate Jenkins' environment as closely as possible. This involves:
- Using the same machine where Jenkins' job runs.
- Employing the same execution method used by Jenkins (except if it's exclusive to the Jenkins plugin).
- Accessing the copy of the source code within the Jenkins workspace.
- To achieve this, you could SSH into the Jenkins machine, navigate to the Jenkins workspace, and manually execute the command (e.g., matlab -batch <your_main_script>) used by Jenkins to run your MATLAB script. This step helps in isolating the problem by confirming if it's specific to Jenkins or related to the environment setup.
3) Review Source Code Management (SCM) Configuration:
- Assess the type of Source Code Management (SCM) system integrated with your Jenkins setup. Understanding whether Jenkins is configured to clone a fresh copy of the project for each build or if updates are manually pulled in on an occasional basis is essential. This information can help in identifying if the issue is related to how the source code is managed and deployed within your Jenkins environment.
By following these troubleshooting steps, you can systematically identify and resolve issues related to executing MATLAB scripts and HIL simulations in a Jenkins environment, ensuring a smoother and more reliable integration process.