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

Commit 0589685

Browse files
authored
Merge pull request #335 from mathworks/new_tmp_dir
Switch to using a temporary directory on the agent external to the WS.
2 parents 7b77260 + ffdc30b commit 0589685

File tree

12 files changed

+44
-123
lines changed

12 files changed

+44
-123
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public String getUrlName() {
6060

6161
public List<BuildArtifactData> getBuildArtifact() throws ParseException, InterruptedException, IOException {
6262
List<BuildArtifactData> artifactData = new ArrayList<BuildArtifactData>();
63-
FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + BUILD_ARTIFACT_FILE));
63+
FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath(), BUILD_ARTIFACT_FILE));
6464
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) {
6565
Object obj = new JSONParser().parse(reader);
6666
JSONObject jo = (JSONObject) obj;

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep
5454
runner.addEnvironmentVariable(
5555
"MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE",
5656
"ciplugins.jenkins.getDefaultPlugins");
57+
runner.addEnvironmentVariable(
58+
"MW_MATLAB_TEMP_FOLDER",
59+
runner.getTempFolder().toString());
5760

5861
// Redirect output to the build annotator
5962
runner.redirectStdOut(annotator);
@@ -83,27 +86,30 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep
8386
annotator.forceEol();
8487

8588
try {
86-
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+
}
87102
} catch (Exception e) {
88103
// Don't want to override more important error
89104
// thrown in catch block
90105
System.err.println(e.toString());
106+
} finally {
107+
try {
108+
this.runner.removeTempFolder();
109+
} catch (Exception e) {
110+
System.err.println(e.toString());
111+
}
91112
}
92113
}
93-
94-
// Handle build result
95-
Run<?,?> build = this.params.getBuild();
96-
FilePath jsonFile = new FilePath(params.getWorkspace(), ".matlab" + File.separator + "buildArtifact.json");
97-
if (jsonFile.exists()) {
98-
FilePath rootLocation = new FilePath(
99-
new File(
100-
build.getRootDir()
101-
.getAbsolutePath()
102-
+ File.separator
103-
+ "buildArtifact.json"));
104-
jsonFile.copyTo(rootLocation);
105-
jsonFile.delete();
106-
build.addAction(new BuildArtifactAction(build));
107-
}
108114
}
109115
}

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)