Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit e6afdca

Browse files
authored
Merge pull request #156 from mathworks/src_folder_doc
document source folder support
2 parents 92ec27f + 6482dd3 commit e6afdca

File tree

2 files changed

+61
-48
lines changed

2 files changed

+61
-48
lines changed

CONFIGDOC.md

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
When you define a [Jenkins™ Pipeline](https://www.jenkins.io/doc/book/pipeline/), whether in the web UI or with a [`Jenkinsfile`](https://www.jenkins.io/doc/book/pipeline/jenkinsfile/), you can use the plugin to run your MATLAB® code or Simulink® models on Jenkins. This guide demonstrates how to configure the plugin and use it in freestyle, multi-configuration, and Pipeline projects.
1+
When you define an automated pipeline of tasks in Jenkins™, whether in the web UI or with a [`Jenkinsfile`](https://www.jenkins.io/doc/book/pipeline/jenkinsfile/), you can use the plugin to run your MATLAB® code or Simulink® models. This guide demonstrates how to configure the plugin and use it in freestyle, multi-configuration, and Pipeline projects.
22

33

44
- [Configure Plugin in Web UI](#configure-plugin-in-web-ui)
@@ -10,8 +10,8 @@ When you define a [Jenkins™ Pipeline](https://www.jenkins.io/doc/book/pipe
1010
- [Set Up Multi-Configuration Project](#set-up-multi-configuration-project)
1111
- [Set Up Pipeline Project](#set-up-pipeline-project)
1212
- [Add MATLAB to System Path](#add-matlab-to-system-path)
13-
- [Use `runMATLABCommand` Step](#use-runmatlabcommand-step)
14-
- [Use `runMATLABTests` Step](#use-runmatlabtests-step)
13+
- [Use the runMATLABCommand Step](#use-the-runmatlabcommand-step)
14+
- [Use the runMATLABTests Step](#use-the-runmatlabtests-step)
1515
- [Use MATLAB in Matrix Build](#use-matlab-in-matrix-build)
1616

1717
## Configure Plugin in Web UI
@@ -20,7 +20,8 @@ You can use the web UI provided by Jenkins to configure the plugin in freestyle
2020
### Use MATLAB in Build
2121
Once you install the plugin, **Use MATLAB version** appears in the **Build Environment** section of the project configuration window.
2222

23-
![matlab_path](https://user-images.githubusercontent.com/48831250/76883191-1c528b00-6852-11ea-9242-7d143f8a5c46.png)
23+
24+
![matlab_path](https://user-images.githubusercontent.com/48831250/94472251-75ec2880-0198-11eb-8d95-7a67c802cae8.png)
2425

2526
Select **Use MATLAB version** to specify the full path to the MATLAB root folder that should be used for the build. The information in the **MATLAB root** box enables the plugin to prepend MATLAB to the system PATH environment variable of the build agent.
2627

@@ -30,9 +31,9 @@ If the build agent already has your desired MATLAB on the path, then you are not
3031

3132
| Platform | Path to MATLAB Root Folder |
3233
|--------------|---------------------------------|
33-
| Windows® | C:\Program Files\MATLAB\R2020a |
34-
| Linux® | /usr/local/MATLAB/R2020a |
35-
| macOS | /Applications/MATLAB_R2020a.app |
34+
| Windows® | C:\Program Files\MATLAB\R2020b |
35+
| Linux® | /usr/local/MATLAB/R2020b |
36+
| macOS | /Applications/MATLAB_R2020b.app |
3637

3738
### Specify Build Steps
3839
When you set up the **Build** section of the project configuration window, the plugin provides you with the **Run MATLAB Command** and **Run MATLAB Tests** build steps.
@@ -44,21 +45,21 @@ The **Run MATLAB Command** build step enables you to specify MATLAB commands tai
4445

4546
If you specify more than one MATLAB command, use a comma or semicolon to separate the commands. The build fails if the execution of any command results in an error.
4647

47-
![run-matlab-command](https://user-images.githubusercontent.com/48831250/79279466-1d400200-7e7c-11ea-9ef5-0d006f100eea.png)
48+
![run_matlab_command](https://user-images.githubusercontent.com/48831250/94472499-d8ddbf80-0198-11eb-8f25-ead3c4039f55.png)
49+
4850

4951
If you need to specify several MATLAB commands, consider writing a MATLAB script or function as part of your repository and executing this script or function instead.
5052

5153
Test artifacts are not autogenerated if you choose to run tests using this build step. You can generate your desired test artifacts by configuring the test runner in the script or function that you invoke from the **Command** box.
5254

5355
#### Run MATLAB Tests
54-
This build step uses a default setting to run tests authored using the MATLAB Unit Testing Framework or Simulink Test™. If your source code is organized into files and folders within a MATLAB project, then the plugin includes any test files in the project that have been labeled as `Test`. If your code does not leverage a MATLAB project or uses a MATLAB release before R2019a, then the plugin includes all tests in the project workspace, including its subfolders.
56+
This build step uses a default setting to run tests authored using the MATLAB Unit Testing Framework or Simulink Test™. If your source code is organized into files and folders within a MATLAB project, then the plugin includes any test files in the project that have been labeled as `Test`. If your code does not leverage a MATLAB project or uses a MATLAB release before R2019a, then the plugin includes all tests in the project workspace, including its subfolders.
5557

56-
The **Run MATLAB Tests** build step enables you to generate different types of test artifacts. To publish the test results, you can use these artifacts with other Jenkins plugins. By default, the plugin assigns a name to each selected artifact and stores it in the `matlabTestArtifacts` folder of the project workspace. You can override the default artifact name and location by specifying a path relative to the project folder in the **File path** box. (If you leave the text box empty, the plugin does not generate an artifact.)
57-
58-
![run_matlab_tests](https://user-images.githubusercontent.com/48831250/84545463-54406180-accd-11ea-890e-7a6bb9ee051b.png)
58+
With the **Run MATLAB Tests** build step, you can optionally specify the location of folders containing source code, relative to the project root folder. When you specify a folder in the **Folder path** box, the plugin adds the specified folder and its subfolders to the top of the MATLAB search path. You can specify more folders by clicking **Add Folder**. If you specify folders, MATLAB uses only the source code in the specified folders and their subfolders to generate a coverage report.
5959

60+
![run_matlab_tests](https://user-images.githubusercontent.com/48831250/94472880-64efe700-0199-11eb-8c2f-e733f104ba95.png)
6061

61-
If you do not select any of the test artifact check boxes, the tests still run, and test failures fail the build.
62+
The **Run MATLAB Tests** build step enables you to generate different types of test artifacts. To publish the test results, you can use these artifacts with other Jenkins plugins. By default, the plugin assigns a name to each selected artifact and stores it in the `matlabTestArtifacts` folder of the project workspace. You can override the default artifact name and location by specifying a path relative to the project folder in the **File path** box. If you leave the text box empty, the plugin does not generate an artifact. If you do not select any of the test artifact check boxes, the tests still run, and test failures fail the build.
6263

6364
The **Run MATLAB Tests** build step produces a MATLAB script file and uses it to run the tests and generate the test artifacts. The plugin writes the contents of this file to the build log. You can review the build log in **Console Output** to understand the testing workflow.
6465

@@ -72,10 +73,11 @@ To configure the plugin for a freestyle project, specify the location where MATL
7273

7374
1) In the **Build Environment** section of the project configuration window, select **Use MATLAB version**. Then, enter the full path to the MATLAB root folder in the **MATLAB root** box. (You can skip this step if MATLAB has already been added to the path on the build agent.)
7475

75-
![build_environment](https://user-images.githubusercontent.com/48831250/76798534-23bc5a80-67a6-11ea-9a48-861cbbc7b0ba.png)
76+
![build_environment](https://user-images.githubusercontent.com/48831250/94472063-31f92380-0198-11eb-90c1-adb48e7f5f2b.png)
77+
7678

7779
2) Add the required build steps in the **Build** section:
78-
* If you add the [**Run MATLAB Tests**](#run-matlab-tests) build step, select check boxes for the artifacts to be generated in the project workspace.
80+
* If you add the [**Run MATLAB Tests**](#run-matlab-tests) build step, specify the source code and the artifacts to be generated in the project workspace.
7981
* If you add the [**Run MATLAB Command**](#run-matlab-command) build step, enter your commands in the **Command** box.
8082

8183
## Set Up Multi-Configuration Project
@@ -87,21 +89,25 @@ To configure the plugin for a multi-configuration project, specify the locations
8789

8890
1) Add a user-defined axis in the **Configuration Matrix** section to represent the MATLAB versions in the build. Specify the name of the axis in the **Name** box and its values in the **Values** box. Separate the values with a space. In this example, four MATLAB versions are specified to run the same set of tests.
8991

90-
![axis_version](https://user-images.githubusercontent.com/48831250/76800706-9a5b5700-67aa-11ea-98f0-25f2b7f3658c.png)
92+
![axis_version](https://user-images.githubusercontent.com/48831250/94473728-96b57d80-019a-11eb-8e53-7e8960430e9b.png)
93+
9194

9295
You can define several axes in the **Configuration Matrix** section. For example, add the TEST_TAG axis specifying the possible test tags for a group of tests.
9396

94-
![axis_version_testtag](https://user-images.githubusercontent.com/48831250/76800736-aa733680-67aa-11ea-86a7-a984d5795e11.png)
97+
![axis_version_testtag](https://user-images.githubusercontent.com/48831250/94474181-4559be00-019b-11eb-9e22-6771f353505b.png)
98+
9599

96100
2) In the **Build Environment** section, select **Use MATLAB version** and then specify the locations where MATLAB is installed using the user-defined axis name. In this example, **$VERSION** in the **MATLAB root** box is replaced by one axis value per build iteration.
97101

98-
![build_environment_matrix](https://user-images.githubusercontent.com/48831250/76800665-87488700-67aa-11ea-9dbd-3c3ab518afa7.png)
102+
![build_environment_matrix](https://user-images.githubusercontent.com/48831250/94474620-e779a600-019b-11eb-8b6a-7e308484c591.png)
103+
99104

100105
3) Add the required build steps in the **Build** section:
101-
* If you add the [**Run MATLAB Tests**](#run-matlab-tests) build step, select check boxes for the artifacts to be generated in the project workspace.
106+
* If you add the [**Run MATLAB Tests**](#run-matlab-tests) build step, specify the source code and the artifacts to be generated in the project workspace.
102107
* If you add the [**Run MATLAB Command**](#run-matlab-command) build step, enter your commands in the **Command** box. You can use the user-defined axes to create your commands. For example:
103108

104-
![run_matlab_command_matrix](https://user-images.githubusercontent.com/48831250/76883848-21fca080-6853-11ea-8ad3-89f85b997608.png)
109+
![run_matlab_command_matrix](https://user-images.githubusercontent.com/48831250/94475242-c9607580-019c-11eb-9ee5-8a0d2f95f5bf.png)
110+
105111

106112
**Note:**
107113
* Both **$VAR** and **${VAR}** are valid formats for accessing the values of the user-defined axis **VAR**. On macOS platforms, the **${VAR}** format is recommended.
@@ -122,16 +128,16 @@ You also can define your Pipeline directly in the project configuration window.
122128
### Add MATLAB to System Path
123129
When Jenkins executes MATLAB-related steps in your Pipeline, it uses the first MATLAB version on the system path. If the PATH environment variable of the build agent does not include any MATLAB versions, you must update the variable with the MATLAB root folder that should be used for the build.
124130

125-
To update the system PATH environment variable using Declarative Pipeline syntax, use an `environment` block in your `Jenkinsfile`. For example, prepend MATLAB R2020a to the system PATH environment variable and use it to run your command.
131+
To update the system PATH environment variable using Declarative Pipeline syntax, use an `environment` block in your `Jenkinsfile`. For example, prepend MATLAB R2020b to the system PATH environment variable and use it to run your command.
126132

127133
```groovy
128134
// Declarative Pipeline
129135
pipeline {
130136
agent any
131137
environment {
132-
PATH = "C:\\Program Files\\MATLAB\\R2020a\\bin;${PATH}" // Windows agent
133-
// PATH = "/usr/local/MATLAB/R2020a/bin:${PATH}" // Linux agent
134-
// PATH = "/Applications/MATLAB_R2020a.app/bin:${PATH}" // macOS agent
138+
PATH = "C:\\Program Files\\MATLAB\\R2020b\\bin;${PATH}" // Windows agent
139+
// PATH = "/usr/local/MATLAB/R2020b/bin:${PATH}" // Linux agent
140+
// PATH = "/Applications/MATLAB_R2020b.app/bin:${PATH}" // macOS agent
135141
}
136142
stages{
137143
stage('Run MATLAB Command') {
@@ -148,14 +154,14 @@ If you define your Pipeline using Scripted Pipeline syntax, set the PATH environ
148154
```groovy
149155
// Scripted Pipeline
150156
node {
151-
env.PATH = "C:\\Program Files\\MATLAB\\R2020a\\bin;${env.PATH}" //Windows agent
152-
// env.PATH = "/usr/local/MATLAB/R2020a/bin:${env.PATH}" //Linux agent
153-
// env.PATH = "/Applications/MATLAB_R2020a.app/bin:${env.PATH}" //macOS agent
157+
env.PATH = "C:\\Program Files\\MATLAB\\R2020b\\bin;${env.PATH}" //Windows agent
158+
// env.PATH = "/usr/local/MATLAB/R2020b/bin:${env.PATH}" //Linux agent
159+
// env.PATH = "/Applications/MATLAB_R2020b.app/bin:${env.PATH}" //macOS agent
154160
runMATLABCommand "disp('Hello World!')"
155161
}
156162
```
157163

158-
### Use `runMATLABCommand` Step
164+
### Use the runMATLABCommand Step
159165
Use the `runMATLABCommand` step in your Pipeline to run MATLAB scripts, functions, and statements tailored to your specific needs. You can use this task to flexibly customize your test run or run any MATLAB commands.
160166

161167
You must provide `runMATLABCommand` with a string that specifies the command you want to execute. If the command is the name of a MATLAB script or function, do not specify the file extension. If you specify more than one MATLAB command, use a comma or semicolon to separate the commands.
@@ -194,7 +200,7 @@ MATLAB exits with exit code 0 if the specified script, function, or statement ex
194200

195201
When you use the `runMATLABCommand` step, all of the required files must be on the MATLAB search path.
196202

197-
### Use `runMATLABTests` Step
203+
### Use the runMATLABTests Step
198204

199205
Use the `runMATLABTests` step in your Pipeline to run all tests in your MATLAB project and generate artifacts. MATLAB includes any files in your project that have a `Test` label. If your Pipeline does not leverage a MATLAB project or uses a MATLAB release before R2019a, then MATLAB includes all tests in the the root of your repository, including its subfolders.
200206

@@ -227,7 +233,7 @@ node {
227233

228234
To generate artifacts using the `runMATLABTests` step, provide the step with one or more name-value pair arguments to specify the artifacts and the locations to save them. Use a colon to separate names and values.
229235

230-
For example, define a Declarative Pipeline to run the tests in your MATLAB project, and then generate a JUnit test results report and a Cobertura code coverage report at specified locations on the build agent.
236+
For example, define a Declarative Pipeline to run the tests in your MATLAB project, and then generate a JUnit test results report and a Cobertura code coverage report at specified locations on the build agent. Generate the coverage report for only the code in the `source` folder located in the root of your repository.
231237

232238

233239
```groovy
@@ -239,7 +245,8 @@ pipeline {
239245
steps
240246
{
241247
runMATLABTests(testResultsJUnit: 'test-results/results.xml',
242-
codeCoverageCobertura: 'code-coverage/coverage.xml')
248+
codeCoverageCobertura: 'code-coverage/coverage.xml',
249+
sourceFolder: ['source'])
243250
}
244251
}
245252
}
@@ -252,7 +259,8 @@ Define a Scripted Pipeline to run your tests and generate artifacts.
252259
// Scripted Pipeline
253260
node {
254261
runMATLABTests(testResultsJUnit: 'test-results/results.xml',
255-
codeCoverageCobertura: 'code-coverage/coverage.xml')
262+
codeCoverageCobertura: 'code-coverage/coverage.xml',
263+
sourceFolder: ['source'])
256264
}
257265
```
258266

@@ -268,12 +276,13 @@ node {
268276
| testResultsSimulinkTest | Path to export Simulink Test Manager results in MLDATX format (requires Simulink Test license and is supported in MATLAB R2019a or later).<br/>**Example:** `'test-results/results.mldatx'` |
269277
| codeCoverageCobertura | Path to write code coverage report in Cobertura XML format.<br/>**Example:** `'code-coverage/coverage.xml'` |
270278
| modelCoverageCobertura | Path to write model coverage report in Cobertura XML format (requires Simulink Coverage™ license and is supported in MATLAB R2018b or later).<br/>**Example:** `'model-coverage/coverage.xml'` |
279+
| sourceFolder | Locations of the folders containing source code, relative to the project root folder. The specified folders and their subfolders are added to the top of the MATLAB search path. To generate a coverage report, MATLAB uses only the source code in the specified folders and their subfolders. <br/>**Example:** `['source']`<br/>**Example:** `['src/folderA', 'src/folderB']` |
271280

272281

273282
## Use MATLAB in Matrix Build
274283
Similar to multi-configuration projects, you can use MATLAB as part of a [matrix](https://www.jenkins.io/doc/book/pipeline/syntax/#declarative-matrix) build in Pipeline projects. For example, you can define a Pipeline to run your test suite on different platforms or against different versions of MATLAB.
275284

276-
This example shows how to define a Declarative Pipeline to run your MATLAB code and generate test artifacts using MATLAB R2018b, R2019a, and R2020a. The Pipeline has a `matrix` section to define the possible name-value combinations that should run in parallel.
285+
This example shows how to define a Declarative Pipeline to run your MATLAB code and generate test artifacts using MATLAB R2018b, R2019a, and R2020b. The Pipeline has a `matrix` section to define the possible name-value combinations that should run in parallel.
277286

278287
```groovy
279288
// Declarative Pipeline
@@ -289,7 +298,7 @@ pipeline {
289298
axes {
290299
axis {
291300
name 'MATLAB_VERSION'
292-
values 'R2018b', 'R2019a', 'R2020a'
301+
values 'R2018b', 'R2019a', 'R2020b'
293302
}
294303
}
295304
stages {

0 commit comments

Comments
 (0)