You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 27, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: CONFIGDOC.md
+117-6Lines changed: 117 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,8 @@ When you define an automated pipeline of tasks in Jenkins™, whether in the
13
13
-[Use the runMATLABCommand Step](#use-the-runmatlabcommand-step)
14
14
-[Use the runMATLABTests Step](#use-the-runmatlabtests-step)
15
15
-[Use MATLAB in Matrix Build](#use-matlab-in-matrix-build)
16
+
-[Register MATLAB as Jenkins Tool](#register-matlab-as-jenkins-tool)
17
+
-[Use MATLAB as a Tool in Pipeline Project](#use-matlab-as-a-tool-in-pipeline-project)
16
18
17
19
## Configure Plugin in Web UI
18
20
You can use the web UI provided by Jenkins to configure the plugin in freestyle and multi-configuration projects. To run MATLAB or Simulink in a Pipeline project, see [Set Up Pipeline Project](#set-up-pipeline-project).
@@ -33,7 +35,7 @@ If the build agent already has your desired MATLAB on the path, then you are not
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.
@@ -55,7 +57,7 @@ Test artifacts are not autogenerated if you choose to run tests using this build
55
57
#### Run MATLAB Tests
56
58
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.
57
59
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.
60
+
With the **Run MATLAB Tests** build step, you can specify the locations of source code folders relative to the project root folder. When you specify a folder in the **Folder path** box, the plugin adds the folder and its subfolders to the top of the MATLAB search path. You can specify more folders by clicking **Add Folder**. If you specify source code folders and then choose to generate a coverage report, MATLAB uses only the code in the specified folders and their subfolders to generate the report.
@@ -119,11 +121,11 @@ When you define your Pipeline with a `Jenkinsfile`, the plugin provides you with
119
121
120
122
To configure the plugin for a Pipeline project:
121
123
1) Define your Pipeline in a `Jenkinsfile` in the root of your repository.
122
-
2) In the **Pipeline** section of the project configuration window, select **Pipeline script from SCM** from the **Definition** drop-down menu.
123
-
3) Select your source control system from the **SCM** drop-down menu.
124
+
2) In the **Pipeline** section of the project configuration window, select **Pipeline script from SCM** from the **Definition** drop-down list.
125
+
3) Select your source control system from the **SCM** drop-down list.
124
126
4) Paste your repository URL into the **Repository URL** box.
125
127
126
-
You also can define your Pipeline directly in the project configuration window. If you select **Pipeline script** from the **Definition** drop-down menu, you can author your Pipeline code in the **Script** box. When you define your Pipeline this way, your Pipeline must include an additional stage to check out MATLAB code from source control.
128
+
You also can define your Pipeline directly in the project configuration window. If you select **Pipeline script** from the **Definition** drop-down list, you can author your Pipeline code in the **Script** box. When you define your Pipeline this way, your Pipeline must include an additional stage to check out MATLAB code from source control.
127
129
128
130
### Add MATLAB to System Path
129
131
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.
@@ -282,7 +284,7 @@ node {
282
284
## Use MATLAB in Matrix Build
283
285
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.
284
286
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.
287
+
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`block to define the possible name-value combinations that should run in parallel.
286
288
287
289
```groovy
288
290
// Declarative Pipeline
@@ -321,6 +323,115 @@ pipeline {
321
323
}
322
324
```
323
325
326
+
## Register MATLAB as Jenkins Tool
327
+
To run MATLAB code and Simulink models as part of your automated pipeline of tasks, Jenkins invokes MATLAB as an external program. When you configure your project, you can explicitly specify the MATLAB version that Jenkins should invoke by providing the path to the desired MATLAB root folder. For example, you can use an `environment` block in your `Jenkinsfile` to specify a MATLAB root folder for your Pipeline project.
328
+
329
+
Instead of specifying the path to the MATLAB root folder on a per project basis, you can register MATLAB as a Jenkins tool, which can then be accessed by any project you configure in Jenkins. To register your desired MATLAB version as a tool, you are required to specify its name and location on the build agent. Once you have registered MATLAB as a tool, you no longer need to specify its root folder path within a project. Jenkins only needs the tool name to access MATLAB.
330
+
331
+
To register MATLAB as a Jenkins tool:
332
+
333
+
1) In your Jenkins interface, select **Manage Jenkins > Global Tool Configuration**. A new page opens where you can register different tools with Jenkins.
334
+
2) In the **MATLAB** section of the **Global Tool Configuration** page, locate and click **Add MATLAB**. The section expands and enables you to specify the name and installation location of MATLAB.
335
+
3) specify the name for your desired MATLAB version in the **Name** box, and enter the full path to the MATLAB root folder in the **MATLAB root** box. To register MATLAB as a tool, you are not required to select **Install automatically**.
336
+
4) To confirm your choices, click **Save** at the bottom of the page.
337
+
338
+
For example, register MATLAB R2020b as a Jenkins tool on your Windows-based local agent.
If your Jenkins instance includes remote agents, you can register MATLAB as a tool on the remote agents using the tool name that you have specified on the local agent. For example, if you have registered MATLAB R2020b as a tool on your local agent, you can register the same MATLAB version installed on a remote agent as a tool on the remote agent. To register MATLAB as a Jenkins tool on a remote agent:
343
+
344
+
1) Navigate to the **Node Properties** interface of the agent. You can access this interface by selecting **Manage Jenkins > Manage Nodes and Clouds**, clicking the link corresponding to the agent, and then selecting **Configure** on the left.
345
+
2) Select **Tool Locations**. Then, select the tool name from the **Name** drop-down list. The list contains the names assigned to the registered MATLAB versions on the local agent.
346
+
3) In the **Home** box, enter the full path to the MATLAB root folder on the remote agent.
347
+
4) Click **Save** to confirm your choices.
348
+
349
+
For example, on a Linux-based remote agent, register MATLAB R2020b as a tool.
**Note:** Currently, using MATLAB as a tool is supported only for Pipeline projects.
354
+
355
+
### Use MATLAB as a Tool in Pipeline Project
356
+
To invoke MATLAB as a Jenkins tool using Declarative Pipeline syntax, use a `tools` block in your `Jenkinsfile`. To specify the tool in the block, use the `matlab` keyword followed by the name assigned to the tool on the **Global Tool Configuration** page. For example, use the MATLAB version that has been defined as a tool named R2020b to run the commands in the file `myscript.m`.
357
+
358
+
```groovy
359
+
// Declarative Pipeline
360
+
pipeline {
361
+
agent any
362
+
tools {
363
+
matlab 'R2020b'
364
+
}
365
+
stages{
366
+
stage('Run MATLAB Command') {
367
+
steps
368
+
{
369
+
runMATLABCommand 'myscript'
370
+
}
371
+
}
372
+
}
373
+
}
374
+
375
+
```
376
+
377
+
If you define your Pipeline using Scripted Pipeline syntax, use the `tool` keyword followed by the name of the tool to retrieve the path to the MATLAB root folder. Then, prepend the path to the `bin` folder of the desired MATLAB version to the PATH environment variable.
378
+
379
+
```groovy
380
+
// Scripted Pipeline
381
+
node {
382
+
def matlabver
383
+
stage('Run MATLAB Command') {
384
+
matlabver = tool 'R2020b'
385
+
if (isUnix()){
386
+
env.PATH = "${matlabver}/bin:${env.PATH}" // Linux or macOS agent
387
+
}else{
388
+
env.PATH = "${matlabver}\\bin;${env.PATH}" // Windows agent
389
+
}
390
+
runMATLABCommand 'myscript'
391
+
}
392
+
}
393
+
```
394
+
You also can invoke MATLAB as a Jenkins tool when you perform a matrix build in your Pipeline project. This example shows how to use three MATLAB versions (specified in an `axis` block using their corresponding tool names) to run a set of MATLAB commands and tests.
0 commit comments