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

Commit 38b9353

Browse files
author
Nikhil Bhoski
committed
Updated tests and added "'" replace logic for tmp folder.
1 parent 4d4bf0f commit 38b9353

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
7272

7373
try {
7474
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
75-
"cd('"+ uniqeTmpFolderPath.getRemote() +"');"+ uniqueCommandFile, uniqueTmpFldrName);
75+
"cd('"+ uniqeTmpFolderPath.getRemote().replaceAll("'", "''") +"');"+ uniqueCommandFile, uniqueTmpFldrName);
7676
listener.getLogger()
7777
.println("#################### Starting command output ####################");
7878
return matlabLauncher.pwd(workspace).join();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
124124

125125
try {
126126
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
127-
"cd('"+ uniqeTmpFolderPath.getRemote() +"');"+ uniqueCommandFile, uniqueTmpFldrName);
127+
"cd('"+ uniqeTmpFolderPath.getRemote().replaceAll("'", "''") +"');"+ uniqueCommandFile, uniqueTmpFldrName);
128128

129129
listener.getLogger()
130130
.println("#################### Starting command output ####################");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void verifyMATLABlaunchedfromWorkspace() throws Exception {
149149
project.getBuildersList().add(this.scriptBuilder);
150150
FreeStyleBuild build = project.scheduleBuild2(0).get();
151151
String workspace = build.getWorkspace().getName();
152-
jenkins.assertLogContains(workspace, build);
152+
jenkins.assertLogContains("[" + workspace + "]", build);
153153
}
154154

155155
/*

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci;
22
/**
33
* Copyright 2020 The MathWorks, Inc.
4-
*
4+
*
55
*/
66

77
import java.io.IOException;
@@ -42,25 +42,24 @@ public void verifyMATLABPathNotSet() throws Exception {
4242
WorkflowRun build = project.scheduleBuild2(0).get();
4343
j.assertLogContains("MATLAB_ROOT", build);
4444
}
45-
45+
4646
/*
4747
* Verify MATLAB gets invoked from workspace.
4848
*/
4949

5050
@Test
5151
public void verifyMATLABstartsInWorkspace() throws Exception {
5252
DumbSlave s = j.createOnlineSlave();
53-
project.setDefinition(new CpsFlowDefinition(
54-
"node('!master') { runMATLABCommand(command: 'pwd')}",
55-
true));
53+
project.setDefinition(
54+
new CpsFlowDefinition("node('!master') { runMATLABCommand(command: 'pwd')}", true));
5655

5756
FilePath workspace = s.getWorkspaceFor(project);
5857
String workspaceName = workspace.getName();
5958
WorkflowRun build = project.scheduleBuild2(0).get();
60-
61-
j.assertLogContains(workspaceName, build);
59+
60+
j.assertLogContains("[" + workspaceName + "]", build);
6261
}
63-
62+
6463
/*
6564
* Verify MATLAB is invoked when valid MATLAB is in PATH.
6665
*
@@ -83,12 +82,11 @@ public void verifyMATLABPathSet() throws Exception {
8382
public void verifyPipelineOnSlave() throws Exception {
8483
DumbSlave s = j.createOnlineSlave();
8584
project.setDefinition(new CpsFlowDefinition(
86-
"node('!master') { testMATLABCommand(command: 'pwd')}",
87-
true));
85+
"node('!master') { testMATLABCommand(command: 'pwd')}", true));
8886

8987
s.getWorkspaceFor(project);
9088
WorkflowRun build = project.scheduleBuild2(0).get();
91-
89+
9290
j.assertBuildStatusSuccess(build);
9391
}
9492

0 commit comments

Comments
 (0)