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

Commit 5088e04

Browse files
authored
Merge branch 'dev_main' into issue_338
2 parents b4a268a + 0589685 commit 5088e04

File tree

12 files changed

+43
-120
lines changed

12 files changed

+43
-120
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public String getUrlName() {
6565

6666
public List<BuildArtifactData> getBuildArtifact() throws ParseException, InterruptedException, IOException {
6767
List<BuildArtifactData> artifactData = new ArrayList<BuildArtifactData>();
68+
6869
FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + BUILD_ARTIFACT_FILE + this.actionID +".json"));
6970
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) {
7071
Object obj = new JSONParser().parse(reader);

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

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep
7171
"MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE",
7272
"ciplugins.jenkins.getDefaultPlugins");
7373
runner.addEnvironmentVariable("MW_BUILD_PLUGIN_ACTION_ID",this.getActionID());
74+
runner.addEnvironmentVariable(
75+
"MW_MATLAB_TEMP_FOLDER",
76+
runner.getTempFolder().toString());
7477

7578
// Redirect output to the build annotator
7679
runner.redirectStdOut(annotator);
@@ -100,27 +103,31 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep
100103
annotator.forceEol();
101104

102105
try {
103-
this.runner.removeTempFolder();
106+
// Handle build result
107+
Run<?,?> build = this.params.getBuild();
108+
FilePath jsonFile = new FilePath(runner.getTempFolder(), "buildArtifact.json");
109+
if (jsonFile.exists()) {
110+
FilePath rootLocation = new FilePath(
111+
new File(
112+
build.getRootDir().getAbsolutePath(),
113+
"buildArtifact.json")
114+
);
115+
jsonFile.copyTo(rootLocation);
116+
jsonFile.delete();
117+
build.addAction(new BuildArtifactAction(build, this.getActionID()));
118+
}
104119
} catch (Exception e) {
105120
// Don't want to override more important error
106121
// thrown in catch block
107122
System.err.println(e.toString());
123+
} finally {
124+
try {
125+
this.runner.removeTempFolder();
126+
} catch (Exception e) {
127+
System.err.println(e.toString());
128+
}
108129
}
109130
}
110131

111-
// Handle build result
112-
Run<?,?> build = this.params.getBuild();
113-
FilePath jsonFile = new FilePath(params.getWorkspace(), ".matlab" + File.separator + "buildArtifact.json");
114-
if (jsonFile.exists()) {
115-
FilePath rootLocation = new FilePath(
116-
new File(
117-
build.getRootDir()
118-
.getAbsolutePath()
119-
+ File.separator
120-
+ "buildArtifact" + this.getActionID() + ".json"));
121-
jsonFile.copyTo(rootLocation);
122-
jsonFile.delete();
123-
build.addAction(new BuildArtifactAction(build, this.getActionID()));
124-
}
125132
}
126133
}

src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import hudson.Launcher;
1919
import hudson.Launcher.ProcStarter;
2020
import hudson.model.Computer;
21+
import hudson.slaves.WorkspaceList;
2122
import hudson.util.ArgumentListBuilder;
2223

2324
import com.mathworks.ci.Utilities;
@@ -43,11 +44,11 @@ public MatlabCommandRunner(MatlabActionParameters params) throws IOException, In
4344
}
4445

4546
// Create MATLAB folder
46-
FilePath matlabFolder = new FilePath(workspace, ".matlab");
47-
matlabFolder.mkdirs();
47+
FilePath tmpRoot = WorkspaceList.tempDir(workspace);
48+
tmpRoot.mkdirs();
4849

4950
// Create temp folder
50-
this.tempFolder = matlabFolder.createTempDir("tempDir", null);
51+
this.tempFolder = tmpRoot.createTempDir("matlab", null);
5152
}
5253

5354
/**

src/main/resources/+ciplugins/+jenkins/BuildReportPlugin.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
function runTaskGraph(plugin, pluginData)
88
[email protected](plugin, pluginData);
9-
[fID, msg] = fopen(fullfile(getenv("WORKSPACE"),".matlab/buildArtifact.json"), "w");
10-
9+
[fID, msg] = fopen(fullfile(getenv("MW_MATLAB_TEMP_FOLDER"),"buildArtifact.json"), "w");
1110
if fID == -1
1211
warning("ciplugins:jenkins:BuildReportPlugin:UnableToOpenFile","Could not open a file for Jenkins build result table due to: %s", msg);
1312
else
@@ -26,4 +25,4 @@ function runTaskGraph(plugin, pluginData)
2625
end
2726
end
2827
end
29-
end
28+
end

src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,4 @@ public void verifyMatrixBuildPasses() throws Exception {
356356
jenkins.assertLogContains("R2018b completed", build);
357357
jenkins.assertBuildStatus(Result.SUCCESS, build);
358358
}
359-
360-
/*
361-
* Test to verify if .matlab temp folder generated in workspace.
362-
*/
363-
@Test
364-
public void verifyMATLABtmpFolderGenerated() throws Exception {
365-
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b")));
366-
project.getBuildWrappersList().add(this.buildWrapper);
367-
scriptBuilder.setTasks("");
368-
project.getBuildersList().add(this.scriptBuilder);
369-
FreeStyleBuild build = project.scheduleBuild2(0).get();
370-
File matlabRunner = new File(build.getWorkspace() + File.separator + ".matlab");
371-
Assert.assertTrue(matlabRunner.exists());
372-
}
373359
}

src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,4 @@ public void verifyExceptionStackTraceForNonZeroExitCode() throws Exception {
176176
j.assertBuildStatus(Result.FAILURE, build);
177177
j.assertLogContains(String.format(Message.getValue("matlab.execution.exception.prefix"), 1), build);
178178
}
179-
180-
/*
181-
* Verify .matlab folder is generated
182-
*/
183-
@Test
184-
public void verifyMATLABtempFolderGenerated() throws Exception {
185-
project.setDefinition(
186-
new CpsFlowDefinition("node { runMATLABBuild() }", true));
187-
188-
WorkflowRun build = project.scheduleBuild2(0).get();
189-
j.assertLogContains(".matlab", build);
190-
}
191179
}

src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -377,18 +377,4 @@ public void verifyMultispecialChar() throws Exception {
377377
jenkins.assertLogContains("Generating MATLAB script with content", build);
378378
jenkins.assertLogContains(expectedCommand, build);
379379
}
380-
381-
/*
382-
* Test to verify if .matlab temp folder generated in workspace.
383-
*/
384-
@Test
385-
public void verifyMATLABtmpFolderGenerated() throws Exception {
386-
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b")));
387-
project.getBuildWrappersList().add(this.buildWrapper);
388-
scriptBuilder.setMatlabCommand("pwd");
389-
project.getBuildersList().add(this.scriptBuilder);
390-
FreeStyleBuild build = project.scheduleBuild2(0).get();
391-
File matlabRunner = new File(build.getWorkspace() + File.separator + ".matlab");
392-
Assert.assertTrue(matlabRunner.exists());
393-
}
394380
}

src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,4 @@ public void verifyExceptionForNonZeroExitCode() throws Exception {
149149
j.assertLogContains(String.format(Message.getValue("matlab.execution.exception.prefix"), 1), build);
150150
j.assertBuildStatusSuccess(build);
151151
}
152-
153-
/*
154-
* Verify .matlab folder is generated
155-
*
156-
*/
157-
158-
@Test
159-
public void verifyMATLABtempFolderGenerated() throws Exception {
160-
project.setDefinition(
161-
new CpsFlowDefinition("node { runMATLABCommand(command: 'pwd')}", true));
162-
163-
WorkflowRun build = project.scheduleBuild2(0).get();
164-
j.assertLogContains(".matlab", build);
165-
}
166152
}

src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTest.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -484,19 +484,6 @@ public void verifyMATLABscratchFileGenerated() throws Exception {
484484
Assert.assertFalse(matlabRunner.exists());
485485
}
486486

487-
/*
488-
* Test to verify if .matlab gets created in workspace.
489-
*/
490-
@Test
491-
public void verifyMATLABfolderGenerated() throws Exception {
492-
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b")));
493-
project.getBuildWrappersList().add(this.buildWrapper);
494-
project.getBuildersList().add(testBuilder);
495-
FreeStyleBuild build = project.scheduleBuild2(0).get();
496-
File matlabRunner = new File(build.getWorkspace() + File.separator + ".matlab");
497-
Assert.assertTrue(matlabRunner.exists());
498-
}
499-
500487
/*
501488
* Test to verify Use Parallel check box present.
502489
*/

src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,6 @@ public void verifyExceptionForNonZeroExitCode() throws Exception {
156156
j.assertLogContains(String.format(Message.getValue("matlab.execution.exception.prefix"), 1), build);
157157
}
158158

159-
/*
160-
* Verify .matlab folder created
161-
*/
162-
163-
@Test
164-
public void verifyMATLABtempFolderGenerated() throws Exception {
165-
project.setDefinition(new CpsFlowDefinition(
166-
"node {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true));
167-
WorkflowRun build = project.scheduleBuild2(0).get();
168-
j.assertLogContains(".matlab", build);
169-
}
170-
171159
/*@Integ Test
172160
* Verify default command options for test Filter using selectByFolder option
173161
*/

0 commit comments

Comments
 (0)