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

Commit ffdc30b

Browse files
committed
Publish build results even if MATLAB exited with nonzero exit code
1 parent af09101 commit ffdc30b

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,6 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep
7878

7979
try {
8080
runner.runMatlabCommand(command);
81-
82-
// Handle build result
83-
Run<?,?> build = this.params.getBuild();
84-
FilePath jsonFile = new FilePath(runner.getTempFolder(), "buildArtifact.json");
85-
if (jsonFile.exists()) {
86-
FilePath rootLocation = new FilePath(
87-
new File(
88-
build.getRootDir().getAbsolutePath(),
89-
"buildArtifact.json")
90-
);
91-
jsonFile.copyTo(rootLocation);
92-
jsonFile.delete();
93-
build.addAction(new BuildArtifactAction(build));
94-
}
9581
} catch (Exception e) {
9682
this.params.getTaskListener().getLogger()
9783
.println(e.getMessage());
@@ -100,11 +86,29 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep
10086
annotator.forceEol();
10187

10288
try {
103-
this.runner.removeTempFolder();
89+
// Handle build result
90+
Run<?,?> build = this.params.getBuild();
91+
FilePath jsonFile = new FilePath(runner.getTempFolder(), "buildArtifact.json");
92+
if (jsonFile.exists()) {
93+
FilePath rootLocation = new FilePath(
94+
new File(
95+
build.getRootDir().getAbsolutePath(),
96+
"buildArtifact.json")
97+
);
98+
jsonFile.copyTo(rootLocation);
99+
jsonFile.delete();
100+
build.addAction(new BuildArtifactAction(build));
101+
}
104102
} catch (Exception e) {
105103
// Don't want to override more important error
106104
// thrown in catch block
107105
System.err.println(e.toString());
106+
} finally {
107+
try {
108+
this.runner.removeTempFolder();
109+
} catch (Exception e) {
110+
System.err.println(e.toString());
111+
}
108112
}
109113
}
110114
}

src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,8 @@ public void shouldCopyBuildResultsToRootAndAddAction() throws IOException, Inter
152152
doReturn(new FilePath(tmp)).when(runner).getTempFolder();
153153
doReturn(dest).when(build).getRootDir();
154154

155-
boolean runTimeException = false;
156-
try {
157-
action.run();
158-
} catch (RuntimeException e) {
159-
runTimeException = true;
160-
}
155+
action.run();
161156

162-
// Should throw for invalid file
163-
assertTrue(runTimeException);
164157
// Should have deleted original file
165158
assertFalse(json.exists());
166159
// Should have copied file to root dir

0 commit comments

Comments
 (0)