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

Commit f84d60e

Browse files
committed
Merge branch 'master' into DATF-1988-add-pdfTestReport
2 parents 06e5262 + 5c9f61a commit f84d60e

File tree

12 files changed

+555
-27
lines changed

12 files changed

+555
-27
lines changed

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Change log
2+
===
3+
4+
### Newer Versions
5+
6+
For newer versions of the plugin, see [GitHub releases.](https://github.com/jenkinsci/matlab-plugin/releases)
7+
8+
### 1.0.3
9+
10+
Release date: _Nov 05, 2019_
11+
12+
* Bug Fix : Scratch file copy is restricted to "Automatic" option.
13+
* README doc updates.
14+
15+
16+
### 1.0.2
17+
18+
Release date: _Aug 21, 2019_
19+
20+
* MATRIX build support.
21+
* Plugin support for older versions of MATLAB until R2013a.
22+
23+
### 1.0.1
24+
25+
Release date: _May 10, 2019_
26+
27+
* Jenkins run-time environment variables support in MATLAB script.
28+
* Enhancement of README with SCM configuration step for "Automatic" Test mode.
29+
30+
### 1.0.0
31+
32+
Release date: _Apr 08, 2019_
33+
34+
* Initial release.
35+
36+
37+
38+
39+

CONFIGDOC.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
## Contents
2+
3+
- [Configure Plugin for Freestyle Project](#configure-plugin-for-freestyle-project)
4+
- [Freestyle Project with Automatic Test Mode](#option-1-freestyle-project-with-automatic-test-mode)
5+
- [Freestyle Project with Custom Test Mode](#option-2-freestyle-project-with-custom-test-mode)
6+
- [Configure Plugin for Multi-Configuration Project](#configure-plugin-for-multi-configuration-project)
7+
- [Multi-Configuration Project with Automatic Test Mode](#option-1-multi-configuration-project-with-automatic-test-mode)
8+
- [Multi-Configuration Project with Custom Test Mode](#option-2-multi-configuration-project-with-custom-test-mode)
9+
10+
## Configure Plugin for Freestyle Project
11+
To configure the plugin for a freestyle project, select **Run MATLAB Tests** from the **Add build step** list. Then, enter the value returned by the **matlabroot** function in the **MATLAB root** field.
12+
13+
![new_add_build_step](https://user-images.githubusercontent.com/47204011/55624172-be54a100-57c2-11e9-9596-52d3a60ee467.png)
14+
15+
![new_enter_matlabroot](https://user-images.githubusercontent.com/51316279/70772996-28830400-1d9c-11ea-92d1-db9f054c304c.png)
16+
17+
### Option 1: Freestyle Project with Automatic Test Mode
18+
With the Jenkins plugin for MATLAB, you have the option to run your tests in either *automatic* or *custom* mode. The automatic test mode employs a default setting to run tests written using the MATLAB Unit Testing Framework and/or Simulink Test. If your source code is organized as files and folders within a project, the plugin will consider any test files in the project that have been tagged as **Test**. If your code does not leverage a project or uses a MATLAB version prior to R2019a, the plugin will consider all tests in the current Jenkins workspace including the subfolders.
19+
20+
If you use a source code management (SCM) system such as Git, then your job must include the appropriate SCM configuration to check out the code before it can invoke the MATLAB plugin. If you do not use any SCM systems to manage your code, then an additional build step is required to ensure that the code is available in the Jenkins workspace before the build starts.
21+
22+
The automatic test execution feature of the plugin enables you to generate different types of test artifacts. To publish the test results, you can use these artifacts with other Jenkins plugins. To configure the Jenkins build where MATLAB tests run automatically, follow these steps.
23+
24+
1) From the **Test mode** drop-down list, select the **Automatic** option (**Automatic** is the default testing mode).
25+
26+
![new_select_automatic_option](https://user-images.githubusercontent.com/51316279/70773784-6719be00-1d9e-11ea-9a6c-7b277d63e10a.png)
27+
28+
2) Select your desired test artifacts.
29+
30+
![new_select_all_test_artifacts](https://user-images.githubusercontent.com/51316279/70773293-0dfd5a80-1d9d-11ea-8d24-28407e67c8a5.png)
31+
32+
The selected artifacts will be saved in the **matlabTestArtifacts** folder of the Jenkins workspace.
33+
34+
![Workspace01](https://user-images.githubusercontent.com/47204011/55470859-1e621080-5626-11e9-98f2-044144272643.JPG)
35+
36+
![Test_artifacts](https://user-images.githubusercontent.com/51316279/70776181-5bc89180-1da2-11ea-92e6-4c71deab7199.png)
37+
38+
If you do not select any of the test artifact check boxes, the **matlabTestArtifacts** folder will not be created in the workspace. However, tests will still run and potential test failures will fail the build.
39+
40+
The **Automatic** test mode results in a MATLAB script file named **runMatlabTests.m** in the Jenkins workspace. The plugin uses this file to run the tests and generate the test artifacts. You can review the contents of the script to understand the testing workflow.
41+
42+
![Workspace01](https://user-images.githubusercontent.com/47204011/55470859-1e621080-5626-11e9-98f2-044144272643.JPG)
43+
44+
### Option 2: Freestyle Project with Custom Test Mode
45+
This option enables you to develop your custom MATLAB commands for running tests. To configure the Jenkins build where you can customize the MATLAB test execution, follow these steps.
46+
47+
1) From the **Test mode** drop-down list, select the **Custom** option.
48+
49+
![new_select_custom](https://user-images.githubusercontent.com/51316279/70775386-42731580-1da1-11ea-9523-41c83443ee5b.png)
50+
51+
2) Enter your commands in the **MATLAB command** field. If you specify more than one MATLAB command, use a comma or semicolon to separate the commands. The build will fail if the execution of any command results in an error.
52+
53+
![new_custom_runtest_command](https://user-images.githubusercontent.com/47204011/55624949-096fb380-57c5-11e9-8711-98baf91816c0.png)
54+
55+
**Note:** If you need several MATLAB commands to run your tests, consider writing a MATLAB script or function as part of your repository and executing this script or function instead. Test artifacts are not autogenerated if you choose to run tests using custom MATLAB commands. You can generate your desired test artifacts by configuring the test runner in the script or function that you invoke from the **MATLAB command** field.
56+
57+
![new_custom_script_example](https://user-images.githubusercontent.com/47204011/55625021-32904400-57c5-11e9-86b7-478b930796c0.png)
58+
59+
## Configure Plugin for Multi-Configuration Project
60+
In addition to freestyle projects, the Jenkins plugin for MATLAB supports [multi-configuration (matrix) projects](https://wiki.jenkins.io/display/JENKINS/Building+a+matrix+project). Multi-configuration projects are useful when builds include similar steps, for example when the same test suite should run on different platforms (e.g., Windows, Linux, and Mac) or using several MATLAB versions.
61+
62+
![image](https://user-images.githubusercontent.com/47204011/62458632-0e586a00-b79b-11e9-8611-3671adb8c289.png)
63+
64+
As in a freestyle project, you can run your tests in automatic or custom mode within a multi-configuration project. The configuration requires you to specify the location where MATLAB is installed as well as the test execution mode. You should also add user-defined axes in the **Configuration Matrix** to specify the duplicating build steps.
65+
66+
### Option 1: Multi-Configuration Project with Automatic Test Mode
67+
68+
To configure the plugin for a matrix build where tests run automatically in multiple MATLAB versions, create a multi-configuration project and follow these steps.
69+
70+
1) Add a user-defined axis in the **Configuration Matrix** to represent the MATLAB versions in the build. Specify the name of the axis in the **Name** field and its values in the **Values** field. Separate the elements in the **Values** field with a space. In this example, four MATLAB versions are specified, which will be used to run the same set of tests.
71+
72+
![image](https://user-images.githubusercontent.com/47204011/62603081-c2c8cc00-b912-11e9-83a4-c5462f58f607.png)
73+
74+
2) In the **Run MATLAB Tests** section of the project, include the user-defined axis name in the **MATLAB root** field to specify the locations where MATLAB is installed. In this example, **$VERSION** will be replaced by one axis value per build step.
75+
76+
![image](https://user-images.githubusercontent.com/51316279/70773424-72b8b500-1d9d-11ea-97ca-807ecd6c4e47.png)
77+
78+
You can select the test artifact check boxes when tests run automatically. Once you have made your selections, save your settings and run the build.
79+
80+
### Option 2: Multi-Configuration Project with Custom Test Mode
81+
82+
To configure the matrix build where you can customize the MATLAB test execution, create a multi-configuration project and follow these steps.
83+
84+
1) Add a user-defined axis in the **Configuration Matrix** to represent the MATLAB versions in the build.
85+
86+
![image](https://user-images.githubusercontent.com/47204011/62603081-c2c8cc00-b912-11e9-83a4-c5462f58f607.png)
87+
88+
2) Add another user-defined axis using the **Add axis** button. In this example, the **TEST_TAG** axis specifies the possible test tags for a group of test elements.
89+
90+
![image](https://user-images.githubusercontent.com/47204011/62517774-b6c30880-b845-11e9-86a0-8344a281fb27.png)
91+
92+
3) In the **Run MATLAB Tests** section of the project, use the **VERSION** axis to specify the locations where MATLAB is installed.
93+
94+
![image](https://user-images.githubusercontent.com/51316279/70773424-72b8b500-1d9d-11ea-97ca-807ecd6c4e47.png)
95+
96+
4) From the **Test mode** drop-down list, select the **Custom** option. Use the second user-defined axis to create your commands and enter them in the **MATLAB command** field. Then, save your settings and run the build.
97+
98+
![image](https://user-images.githubusercontent.com/47204011/62686681-cd529680-b9e2-11e9-82c1-c211f1740be4.png)
99+
100+
**Notes:**
101+
1) For a user-defined axis named **VAR**, **$VAR** and **${VAR}** are both valid formats for accessing the values.
102+
103+
2) A multi-configuration project creates a separate workspace for each user-defined axis value. If you specify the full paths to where MATLAB is installed as axis values, Jenkins fails to create separate workspaces and fails the build.

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ The Jenkins plugin for MATLAB® enables you to easily run your MATLAB and Sim
44

55
*Note: Producing a PDF test report is not supported on Mac OS platform.*
66

7-
## Configure Plugin for Freestyle Project
8-
To configure the plugin for a freestyle project, select **Run MATLAB Tests** from the **Add build step** list. Then, enter the value returned by the **matlabroot** function in the **MATLAB root** field.
7+
## Documentation
98

9+
<<<<<<< HEAD
1010
![new_add_build_step](https://user-images.githubusercontent.com/47204011/55624172-be54a100-57c2-11e9-9596-52d3a60ee467.png)
1111

1212
![new_enter_matlabroot](https://user-images.githubusercontent.com/51316279/67834674-085df500-fb0e-11e9-927b-c4da6bff0ed6.png)
@@ -98,7 +98,14 @@ To configure the matrix build where you can customize the MATLAB test execution,
9898
1) For a user-defined axis named **VAR**, **$VAR** and **${VAR}** are both valid formats for accessing the values.
9999

100100
2) A multi-configuration project creates a separate workspace for each user-defined axis value. If you specify the full paths to where MATLAB is installed as axis values, Jenkins fails to create separate workspaces and fails the build.
101+
=======
102+
#### Configuration Steps
103+
* To learn how to configure the Jenkins Plugin for MATLAB, see the [plugin configuration guide.](/CONFIGDOC.md)
101104

105+
#### Change Log
106+
>>>>>>> master
107+
108+
* For a detailed list of releases, see [Change logs](/CHANGELOG.md).
102109

103110
## Contact Us
104111
If you have any questions or suggestions, please contact MathWorks.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<relativePath />
99
</parent>
1010
<artifactId>matlab</artifactId>
11-
<version>1.0.4-SNAPSHOT</version>
11+
<version>1.1.2-SNAPSHOT</version>
1212
<packaging>hpi</packaging>
1313

1414
<developers>
@@ -26,7 +26,7 @@
2626

2727
<name>MATLAB Plugin</name>
2828
<description>Jenkins plugin for MATLAB</description>
29-
<url>https://wiki.jenkins.io/display/JENKINS/MATLAB+Plugin</url>
29+
<url>https://github.com/jenkinsci/matlab-plugin</url>
3030
<licenses>
3131
<license>
3232
<name>MIT License</name>

src/main/java/com/mathworks/ci/MatlabBuilder.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.function.Function;
2222
import javax.annotation.Nonnull;
2323
import org.apache.commons.io.FilenameUtils;
24+
import org.apache.commons.lang.ArrayUtils;
2425
import org.kohsuke.stapler.DataBoundConstructor;
2526
import org.kohsuke.stapler.DataBoundSetter;
2627
import org.kohsuke.stapler.QueryParameter;
@@ -52,6 +53,7 @@ public class MatlabBuilder extends Builder implements SimpleBuildStep {
5253
private TestRunTypeList testRunTypeList;
5354
private String matlabRoot;
5455
private EnvVars env;
56+
private MatlabReleaseInfo matlabRel;
5557
private String nodeSpecificfileSeparator;
5658

5759
@DataBoundConstructor
@@ -488,6 +490,9 @@ public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace,
488490
throws InterruptedException, IOException {
489491
//Set the environment variable specific to the this build
490492
setEnv(build.getEnvironment(listener));
493+
//Get node specific matlabroot to get matlab version information
494+
FilePath nodeSpecificMatlabRoot = new FilePath(launcher.getChannel(),getLocalMatlab());
495+
matlabRel = new MatlabReleaseInfo(nodeSpecificMatlabRoot);
491496
nodeSpecificfileSeparator = getNodeSpecificFileSeperator(launcher);
492497

493498
// Invoke MATLAB command and transfer output to standard
@@ -505,10 +510,8 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
505510
throws IOException, InterruptedException {
506511
ProcStarter matlabLauncher;
507512
try {
508-
FilePath nodeSpecificMatlabRoot = new FilePath(launcher.getChannel(),getLocalMatlab());
509-
MatlabReleaseInfo rel = new MatlabReleaseInfo(nodeSpecificMatlabRoot);
510513
matlabLauncher = launcher.launch().pwd(workspace).envs(this.env);
511-
if (rel.verLessThan(MatlabBuilderConstants.BASE_MATLAB_VERSION_BATCH_SUPPORT)) {
514+
if (matlabRel.verLessThan(MatlabBuilderConstants.BASE_MATLAB_VERSION_BATCH_SUPPORT)) {
512515
ListenerLogDecorator outStream = new ListenerLogDecorator(listener);
513516
matlabLauncher = matlabLauncher.cmds(constructDefaultMatlabCommand(launcher.isUnix())).stderr(outStream);
514517
} else {
@@ -551,7 +554,7 @@ public List<String> constructMatlabCommandWithBatch() {
551554
return matlabDefaultArgs;
552555
}
553556

554-
public List<String> constructDefaultMatlabCommand(boolean isLinuxLauncher) {
557+
public List<String> constructDefaultMatlabCommand(boolean isLinuxLauncher) throws MatlabVersionNotFoundException {
555558
final List<String> matlabDefaultArgs = new ArrayList<String>();
556559
Collections.addAll(matlabDefaultArgs, getPreRunnerSwitches());
557560
if (!isLinuxLauncher) {
@@ -566,10 +569,13 @@ public List<String> constructDefaultMatlabCommand(boolean isLinuxLauncher) {
566569
}
567570

568571

569-
private String[] getPreRunnerSwitches() {
572+
private String[] getPreRunnerSwitches() throws MatlabVersionNotFoundException {
570573
String[] preRunnerSwitches =
571574
{getLocalMatlab() + nodeSpecificfileSeparator + "bin" + nodeSpecificfileSeparator + "matlab", "-nosplash",
572-
"-nodesktop", "-noAppIcon"};
575+
"-nodesktop"};
576+
if(!matlabRel.verLessThan(MatlabBuilderConstants.BASE_MATLAB_VERSION_NO_APP_ICON_SUPPORT)) {
577+
preRunnerSwitches = (String[]) ArrayUtils.add(preRunnerSwitches, "-noAppIcon");
578+
}
573579
return preRunnerSwitches;
574580
}
575581

src/main/java/com/mathworks/ci/MatlabBuilderConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
public class MatlabBuilderConstants {
77
static final double BASE_MATLAB_VERSION_RUNTESTS_SUPPORT = 8.1;
8+
static final double BASE_MATLAB_VERSION_NO_APP_ICON_SUPPORT = 8.6;
89
static final double BASE_MATLAB_VERSION_BATCH_SUPPORT = 9.5;
910
static final double BASE_MATLAB_VERSION_COBERTURA_SUPPORT = 9.3;
1011
static final double BASE_MATLAB_VERSION_MODELCOVERAGE_SUPPORT = 9.5;

src/main/java/com/mathworks/ci/MatlabReleaseInfo.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
package com.mathworks.ci;
22

3+
import java.io.BufferedReader;
4+
35
/*
46
* Copyright 2019 The MathWorks, Inc. This Class provides MATLAB release information in the form of
57
* Version numbers. Class constructor requires MATLAB root as input parameter
68
*/
79

8-
import java.io.File;
9-
import java.io.IOException;
10+
import java.io.InputStream;
11+
import java.io.InputStreamReader;
12+
import java.nio.charset.StandardCharsets;
1013
import java.nio.file.NotDirectoryException;
1114
import java.util.HashMap;
1215
import java.util.Map;
16+
import java.util.regex.Matcher;
17+
import java.util.regex.Pattern;
18+
1319
import javax.xml.parsers.DocumentBuilder;
1420
import javax.xml.parsers.DocumentBuilderFactory;
1521
import org.apache.commons.collections.MapUtils;
16-
import org.jenkinsci.remoting.RoleChecker;
1722
import org.w3c.dom.Document;
1823
import org.w3c.dom.Element;
1924
import org.w3c.dom.Node;
2025
import org.w3c.dom.NodeList;
2126
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2227
import hudson.FilePath;
23-
import hudson.FilePath.FileCallable;
24-
import hudson.remoting.VirtualChannel;
2528

2629
public class MatlabReleaseInfo {
2730
private FilePath matlabRoot;
2831
private static final String VERSION_INFO_FILE = "VersionInfo.xml";
32+
private static final String CONTENTS_FILE = "toolbox/matlab/general/Contents.m";
33+
private static final String VERSION_PATTERN = "(\\d+)\\.(\\d+)";
2934
private static final String VERSION_INFO_ROOT_TAG = "MathWorks_version_info";
3035
private static final String RELEASE_TAG = "release";
3136
private static final String VERSION_TAG = "version";
3237
private static final String DESCRIPTION_TAG = "description";
3338
private static final String DATE_TAG = "date";
34-
private static final String VERSION_16B = "9.1.0.888888";
35-
private static final Map<String, String> VERSION_OLDER_THAN_17A = new HashMap<String, String>(){
36-
{
37-
put(VERSION_TAG,VERSION_16B);
38-
}
39-
};
4039

4140
private Map<String, String> versionInfoCache = new HashMap<String, String>();
4241

@@ -107,14 +106,31 @@ private Map<String, String> getVersionInfoFromFile() throws MatlabVersionNotFoun
107106
else if(!this.matlabRoot.exists()){
108107
throw new NotDirectoryException("Invalid matlabroot path");
109108
}else {
110-
versionInfoCache.putAll(VERSION_OLDER_THAN_17A);
111-
}
112-
109+
// Get the version information from Contents.m file when VersionInfo.xml is not
110+
// present.
111+
FilePath contentFile = new FilePath(this.matlabRoot, CONTENTS_FILE);
112+
String actualVersion = null;
113+
try (InputStream in = contentFile.read();
114+
BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
115+
116+
// Skip first line and capture the second line.
117+
br.readLine();
118+
String versionLine = br.readLine();
119+
120+
Pattern p = Pattern.compile(VERSION_PATTERN);
121+
Matcher m = p.matcher(versionLine);
122+
if (m.find()) {
123+
actualVersion = m.group();
124+
}
125+
}
126+
// Update the versionInfoCache with actual version extracted from Contents.m
127+
versionInfoCache.put(VERSION_TAG, actualVersion);
128+
}
113129
} catch (Exception e) {
114130
throw new MatlabVersionNotFoundException(
115131
Message.getValue("Releaseinfo.matlab.version.not.found.error"), e);
116-
}
132+
}
117133
}
118134
return versionInfoCache;
119135
}
120-
}
136+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<div>
2-
Enter the full path to the MATLAB root folder, which is returned by the <i><b>matlabroot</b></i> function. <br><br>Example:<br><br><i><b><u>Windows:</u><b></i><br> C:\Program Files\MATLAB\R2019a <br>
2+
Enter the full path to the MATLAB root folder, which is returned by the <i><b>matlabroot</b></i> function. <br><br>Example:<br><br><i><b><u>Windows:</u></b></i><br> C:\Program Files\MATLAB\R2019a <br>
33
<i><b><u>Linux:</u></b></i><br> /usr/local/MATLAB/R2019a <br>
44
<i><b><u>Mac:</u></b></i><br> /Applications/MATLAB_R2019a.app <br>
5+
<p>
6+
<b>Note:</b> If the job runs on a remote agent, you must specify the full path to MATLAB root folder on the remote agent.</p>
57
</div>

0 commit comments

Comments
 (0)