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

Commit 72af6c0

Browse files
authored
Merge pull request #388 from mathworks/2.16.0-SNAPSHOT-Qualification
2.16.0 snapshot qualification
2 parents cfd9617 + 23097aa commit 72af6c0

File tree

15 files changed

+394
-241
lines changed

15 files changed

+394
-241
lines changed

CONFIGDOC.md

+200-76
Large diffs are not rendered by default.

examples/Run-MATLAB-Tests.md

+16-12
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,46 @@ To follow the steps in this example:
1818

1919
* MATLAB and the plugin for MATLAB must be installed on your Jenkins server. For information on how to install a plugin in Jenkins, see [Managing Plugins](https://jenkins.io/doc/book/managing/plugins/).
2020
* The Times Table App project must be under source control. For example, you can create a new repository for the project using your GitHub® account. For more information, see [Use Source Control with Projects](https://www.mathworks.com/help/matlab/matlab_prog/use-source-control-with-projects.html).
21-
* The [Cobertura](https://plugins.jenkins.io/cobertura) and [JUnit](https://plugins.jenkins.io/junit) plugins must be installed. These plugins are required to publish the artifacts using post-build actions.
21+
* The [coverage](https://plugins.jenkins.io/coverage/) and [JUnit](https://plugins.jenkins.io/junit) plugins must be installed. These plugins are required to publish the artifacts using post-build actions.
2222

2323
## Create a Freestyle Project to Run MATLAB Tests
2424
Create a new project and configure it by following these steps:
2525
1. In your Jenkins interface, select **New Item** on the left. A new page opens where you can choose the type of your project. Enter a project name, and then click **Freestyle project**. To confirm your choices, click **OK**.
2626

27-
![create_project](https://github.com/mathworks/jenkins-matlab-plugin/assets/48831250/8aa314b3-60fc-4534-bd49-223617ca0542)
27+
![create_project](https://github.com/user-attachments/assets/cedd846b-4460-43d7-9278-253c7ee7260e)
2828

2929
2. On the project configuration page, in the **Source Code Management** section, specify the repository that hosts your tests.
3030

31-
![source_control](https://github.com/mathworks/jenkins-matlab-plugin/assets/48831250/5befa3c5-6924-4abb-bc34-25ff3328ee47)
31+
![source_control](https://github.com/user-attachments/assets/3b888ed9-b521-4c3c-a932-ad5f9de563c3)
3232

33-
3. In the **Build Environment** section, select **Use MATLAB version** and specify the MATLAB version you want to use in the build. If your preferred MATLAB version is not listed under **Use MATLAB version**, enter the full path to its root folder in the **MATLAB root** box.
33+
3. In the **Environment** section, select **Use MATLAB version** and specify the MATLAB version you want to use in the build. If your preferred MATLAB version is not listed under **Use MATLAB version**, enter the full path to its root folder in the **MATLAB root** box.
3434

35-
![build_environment](https://github.com/mathworks/jenkins-matlab-plugin/assets/48831250/c77220c0-a521-41ad-b0e4-76a6f0afce28)
35+
![environment](https://github.com/user-attachments/assets/00598e0c-468d-465b-b334-5c7ed750ee3f)
3636

3737
4. In the **Build Steps** section, select **Add build step > Run MATLAB Tests**. Then, specify the artifacts to generate in the project workspace. In this example, the plugin generates test results in JUnit-style XML format and code coverage results in Cobertura XML format. Furthermore, to generate the coverage results, the plugin uses only the code in the `source` folder located in the root of the repository. For more information about the build steps provided by the plugin, see [Plugin Configuration Guide](../CONFIGDOC.md).
3838

39-
![run_matlab_tests](https://github.com/mathworks/jenkins-matlab-plugin/assets/48831250/2ef326b7-9b39-4068-83b9-011cebd52506)
39+
![run_matlab_tests](https://github.com/user-attachments/assets/b6b7b811-d998-4fb9-bbf8-5de624bb5bd6)
4040

41-
5. In the **Post-build Actions** section, add two post-build actions to publish the JUnit-style test results and the Cobertura code coverage results. For each artifact, provide the path to the report.
41+
5. In the **Post-build Actions** section, add the **Publish JUnit test result report** post-build action to publish the test results in JUnit-style XML format. Specify the path to the test report in the **Test report XMLs** box.
4242

43-
![post_build](https://github.com/mathworks/jenkins-matlab-plugin/assets/48831250/d584a290-de93-4a9f-8061-00bc2a435c12)
43+
![post_build_junit](https://github.com/user-attachments/assets/82b4c99a-59c3-41e4-946d-555fb9315f35)
4444

45-
6. Click **Save** to save the project configuration settings. You can access and modify your settings at a later stage by selecting **Configure** in the project interface, which displays the project name at the upper-left corner of the page.
45+
6. In the **Post-build Actions** section, add the **Record code coverage results** post-build action to publish the code coverage results in Cobertura XML format. Select `Cobertura Coverage Reports` from the **Coverage Parser** list and specify the path to the coverage report in the **Report File Pattern** box.
46+
47+
![post_build_cobertura](https://github.com/user-attachments/assets/5af14bb9-f12e-4942-a3ad-957eec4a057b)
48+
49+
7. Click **Save** to save the project configuration settings. You can access and modify your settings at a later stage by selecting **Configure** in the project interface, which displays the project name at the upper-left corner of the page.
4650

4751
## Run Tests and Inspect Artifacts
48-
To build your freestyle project, select **Build Now** in the project interface. Jenkins triggers a build, assigns it a number under **Build History**, and runs the build. In this example, the build succeeds because all the tests in the Times Table App project pass.
52+
To build your freestyle project, select **Build Now** in the project interface. Jenkins triggers a build, assigns it a number under **Builds**, and runs the build. In this example, the build succeeds because all the tests in the Times Table App project pass.
4953

5054
Navigate to the project workspace by selecting **Workspace** in the project interface. The generated artifacts are in the `matlabTestArtifacts` folder of the workspace.
5155

52-
![workspace](https://github.com/mathworks/jenkins-matlab-plugin/assets/48831250/5195fb71-6f4f-4261-82c0-501ab953a079)
56+
![workspace](https://github.com/user-attachments/assets/1c1ff1f8-99b7-475f-8278-180ab0185833)
5357

5458
Select **Status** in the project interface. You can access the published artifacts by clicking the **Latest Test Result** and **Coverage Report** links. For example, click the **Latest Test Result** link to view the published JUnit-style test results. On the test results page, click the **(root)** link in the **All Tests** table. The table expands and lists information for each of the test classes within the Times Table App project.
5559

56-
![test_results](https://github.com/mathworks/jenkins-matlab-plugin/assets/48831250/2dc5142d-b844-436c-8e9e-8f7b90c7b69e)
60+
![test_results](https://github.com/user-attachments/assets/51cc73aa-cf8b-455a-b210-7ecfbb772a72)
5761

5862
## See Also
5963
* [Plugin Configuration Guide](../CONFIGDOC.md)<br/>

pom.xml

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
35
<modelVersion>4.0.0</modelVersion>
46
<parent>
57
<groupId>org.jenkins-ci.plugins</groupId>
@@ -56,8 +58,6 @@
5658
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
5759
<jenkins.baseline>2.387</jenkins.baseline>
5860
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
59-
<!-- TODO fix violations -->
60-
<spotbugs.threshold>High</spotbugs.threshold>
6161
</properties>
6262

6363
<dependencyManagement>
@@ -132,8 +132,7 @@
132132
<groupId>org.jenkins-ci.tools</groupId>
133133
<artifactId>maven-hpi-plugin</artifactId>
134134
</plugin>
135-
<!-- Plugin to download the matlab run scripts and keep it under class
136-
resource folder -->
135+
<!-- Plugin to download the matlab run scripts and keep it under class resource folder -->
137136
<plugin>
138137
<groupId>com.googlecode.maven-download-plugin</groupId>
139138
<artifactId>download-maven-plugin</artifactId>
@@ -146,7 +145,8 @@
146145
<goal>wget</goal>
147146
</goals>
148147
<configuration>
149-
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/glnxa64/run-matlab-command</url>
148+
<url>
149+
https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/glnxa64/run-matlab-command</url>
150150
<unpack>false</unpack>
151151
<outputDirectory>${basedir}/src/main/resources/glnxa64</outputDirectory>
152152
<skipCache>true</skipCache>
@@ -160,7 +160,8 @@
160160
<goal>wget</goal>
161161
</goals>
162162
<configuration>
163-
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/maci64/run-matlab-command</url>
163+
<url>
164+
https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/maci64/run-matlab-command</url>
164165
<unpack>false</unpack>
165166
<outputDirectory>${basedir}/src/main/resources/maci64</outputDirectory>
166167
<skipCache>true</skipCache>
@@ -174,7 +175,8 @@
174175
<goal>wget</goal>
175176
</goals>
176177
<configuration>
177-
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/maca64/run-matlab-command</url>
178+
<url>
179+
https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/maca64/run-matlab-command</url>
178180
<unpack>false</unpack>
179181
<outputDirectory>${basedir}/src/main/resources/maca64</outputDirectory>
180182
<skipCache>true</skipCache>
@@ -188,7 +190,8 @@
188190
<goal>wget</goal>
189191
</goals>
190192
<configuration>
191-
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/win64/run-matlab-command.exe</url>
193+
<url>
194+
https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/win64/run-matlab-command.exe</url>
192195
<unpack>false</unpack>
193196
<outputDirectory>${basedir}/src/main/resources/win64</outputDirectory>
194197
<skipCache>true</skipCache>
@@ -202,7 +205,8 @@
202205
<goal>wget</goal>
203206
</goals>
204207
<configuration>
205-
<url>https://ssd.mathworks.com/supportfiles/ci/matlab-script-generator/v0/matlab-script-generator.zip</url>
208+
<url>
209+
https://ssd.mathworks.com/supportfiles/ci/matlab-script-generator/v0/matlab-script-generator.zip</url>
206210
<unpack>false</unpack>
207211
<outputDirectory>${basedir}/src/main/resources</outputDirectory>
208212
<skipCache>true</skipCache>
@@ -214,8 +218,8 @@
214218
</plugins>
215219
<pluginManagement>
216220
<plugins>
217-
<!--This plugin's configuration is used to store Eclipse m2e settings
218-
only. It has no influence on the Maven build itself. -->
221+
<!-- This plugin's configuration is used to store Eclipse m2e settings only. It has
222+
no influence on the Maven build itself. -->
219223
<plugin>
220224
<groupId>org.eclipse.m2e</groupId>
221225
<artifactId>lifecycle-mapping</artifactId>

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

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import com.google.common.annotations.VisibleForTesting;
8-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
98
import hudson.Extension;
109
import hudson.MarkupText;
1110
import hudson.console.ConsoleAnnotationDescriptor;
@@ -15,7 +14,6 @@
1514

1615
public class BuildTargetNote extends ConsoleNote {
1716
@VisibleForTesting
18-
@SuppressFBWarnings(value = "MS_SHOULD_BE_FINAL", justification = "Visible for testing")
1917
public static boolean ENABLED = !Boolean.getBoolean(BuildTargetNote.class.getName() + ".disabled");
2018

2119
public BuildTargetNote() {

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

+4-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* Describable class for adding MATLAB installations in Jenkins Global Tool configuration.
77
*/
88

9-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
109
import hudson.CopyOnWrite;
1110
import hudson.EnvVars;
1211
import hudson.Extension;
@@ -15,15 +14,12 @@
1514
import hudson.model.EnvironmentSpecific;
1615
import hudson.model.Node;
1716
import hudson.model.TaskListener;
18-
import hudson.remoting.VirtualChannel;
1917
import hudson.slaves.NodeSpecific;
2018
import hudson.tools.ToolDescriptor;
2119
import hudson.tools.ToolInstallation;
2220
import hudson.tools.ToolProperty;
2321
import java.io.File;
2422
import java.io.IOException;
25-
import java.nio.file.Path;
26-
import java.nio.file.Paths;
2723
import java.util.Arrays;
2824
import java.util.List;
2925
import javax.annotation.CheckForNull;
@@ -62,22 +58,13 @@ public MatlabInstallation forNode(@Nonnull Node node, TaskListener log) throws I
6258
return new MatlabInstallation(getName(), translateFor(node, log), getProperties().toList());
6359
}
6460

65-
@SuppressFBWarnings(value = {
66-
"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" }, justification = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions "
67-
+ "https://github.com/spotbugs/spotbugs/issues/1843")
6861
@Override
6962
public void buildEnvVars(EnvVars env) {
70-
String pathToExecutable = getHome() + "/bin";
71-
env.put("PATH+matlabroot", pathToExecutable);
72-
Jenkins jenkinsInstance = Jenkins.getInstanceOrNull();
73-
if (jenkinsInstance != null) {
74-
if (jenkinsInstance.getChannel() != null) {
75-
FilePath batchExecutablePath = new FilePath(jenkinsInstance.getChannel(), getHome());
76-
if (batchExecutablePath.getParent() != null) {
77-
env.put("PATH+matlab_batch", batchExecutablePath.getParent().getRemote());
78-
}
79-
}
63+
String home = getHome();
64+
if (home == null) {
65+
return;
8066
}
67+
env.put("PATH+matlabroot", home + "/bin");
8168
}
8269

8370
public static MatlabInstallation[] getAll() {

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
import java.io.InputStream;
1111
import java.io.InputStreamReader;
12+
import java.io.IOException;
1213
import java.io.BufferedReader;
14+
import java.lang.InterruptedException;
1315
import java.nio.charset.StandardCharsets;
1416
import java.nio.file.NotDirectoryException;
1517
import java.util.HashMap;
@@ -25,7 +27,7 @@
2527
import org.w3c.dom.Element;
2628
import org.w3c.dom.Node;
2729
import org.w3c.dom.NodeList;
28-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
30+
import org.xml.sax.SAXException;
2931
import hudson.FilePath;
3032

3133
public class MatlabReleaseInfo {
@@ -74,11 +76,6 @@ public boolean verLessThan(double version) throws MatlabVersionNotFoundException
7476
}
7577
}
7678

77-
@SuppressFBWarnings(value = { "REC_CATCH_EXCEPTION",
78-
"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE" }, justification = "REC_CATCH_EXCEPTION: Irrespective of exception type, intention is to handle it in same way."
79-
+
80-
" Also, there is no intention to propagate any runtime exception up in the hierarchy." +
81-
"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE: This is a false positive reported by spotbugs for JDK 11 for try-with-resources block.")
8279
private Map<String, String> getVersionInfoFromFile() throws MatlabVersionNotFoundException {
8380
if (MapUtils.isEmpty(versionInfoCache)) {
8481
try {
@@ -139,7 +136,7 @@ private Map<String, String> getVersionInfoFromFile() throws MatlabVersionNotFoun
139136
// Update the versionInfoCache with actual version extracted from Contents.m
140137
versionInfoCache.put(VERSION_TAG, actualVersion);
141138
}
142-
} catch (Exception e) {
139+
} catch (InterruptedException | IOException | ParserConfigurationException | SAXException e) {
143140
throw new MatlabVersionNotFoundException(
144141
Message.getValue("Releaseinfo.matlab.version.not.found.error"), e);
145142
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ public class MatlabVersionNotFoundException extends Exception {
1111
MatlabVersionNotFoundException(String errorMessage, Throwable err) {
1212
super(errorMessage, err);
1313
}
14+
15+
MatlabVersionNotFoundException(String errorMessage) {
16+
super(errorMessage);
17+
}
1418
}

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

+5-21
Original file line numberDiff line numberDiff line change
@@ -197,39 +197,23 @@ public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher
197197
if (!matlabExecutablePath.exists()) {
198198
throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error"));
199199
}
200-
// Add matlab-batch executable in path
201-
FilePath batchExecutable = getNthParentFilePath(matlabExecutablePath, 3);
202-
if (batchExecutable != null && batchExecutable.exists()) {
203-
context.env("PATH+matlab_batch", batchExecutable.getRemote());
200+
FilePath matlabBinDir = matlabExecutablePath.getParent();
201+
if (matlabBinDir == null) {
202+
throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error"));
204203
}
205204

206205
// Add "matlabroot" without bin as env variable which will be available across
207206
// the build.
208207
context.env("matlabroot", nodeSpecificMatlab);
209208
// Add matlab bin to path to invoke MATLAB directly on command line.
210-
context.env("PATH+matlabroot", matlabExecutablePath.getParent().getRemote());
209+
context.env("PATH+matlabroot", matlabBinDir.getRemote());
211210
;
212211
listener.getLogger().println("\n" + String.format(Message.getValue("matlab.added.to.path.from"),
213-
matlabExecutablePath.getParent().getRemote()) + "\n");
212+
matlabBinDir.getRemote()) + "\n");
214213
}
215214

216215
private String getNodeSpecificExecutable(Launcher launcher) {
217216
return (launcher.isUnix()) ? "/bin/matlab" : "\\bin\\matlab.exe";
218217
}
219218

220-
public static FilePath getNthParentFilePath(FilePath path, int levels) {
221-
if (path == null || levels < 0) {
222-
return null;
223-
}
224-
225-
FilePath currentPath = path;
226-
for (int i = 0; i < levels; i++) {
227-
if (currentPath == null) {
228-
return null;
229-
}
230-
currentPath = currentPath.getParent();
231-
}
232-
return currentPath;
233-
}
234-
235219
}

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

+4-10
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,14 @@ public static void addMatlabToEnvPathFromAxis(Computer cmp, TaskListener listene
4040
return;
4141
}
4242

43-
FilePath matlabRoot = getNodeSpecificHome(name,
44-
cmp.getNode(), listener, env);
43+
FilePath matlabRoot = getNodeSpecificHome(name, cmp.getNode(), listener, env);
4544

46-
if (matlabRoot != null && matlabRoot.getParent().exists()) {
47-
env.put("PATH+matlab_batch", matlabRoot.getParent().getRemote());
48-
}
49-
50-
String matlabExecutablePath = getNodeSpecificHome(name,
51-
cmp.getNode(), listener, env).getRemote() + ((Boolean.TRUE.equals(cmp.isUnix())) ? "/bin" : "\\bin");
52-
env.put("PATH+matlabroot", matlabExecutablePath);
45+
FilePath matlabBin = new FilePath(matlabRoot, "bin");
46+
env.put("PATH+matlabroot", matlabBin.getRemote());
5347

5448
// Specify which MATLAB was added to path.
5549
listener.getLogger().println(
56-
"\n" + String.format(Message.getValue("matlab.added.to.path.from"), matlabExecutablePath) + "\n");
50+
"\n" + String.format(Message.getValue("matlab.added.to.path.from"), matlabBin.getRemote()) + "\n");
5751
}
5852

5953
public static FilePath getNodeSpecificHome(String instName, Node node, TaskListener listener, EnvVars env)

0 commit comments

Comments
 (0)