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

Commit bb089ae

Browse files
author
Nikhil Bhoski
committed
Run MATLAB command using cd and invoke MATLAB from workspace.
1 parent cfec84c commit bb089ae

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
7272

7373
try {
7474
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
75-
uniqueCommandFile, uniqueTmpFldrName);
76-
launcher.launch().pwd(uniqeTmpFolderPath).envs(envVars);
75+
"cd('"+ uniqeTmpFolderPath.getRemote() +"');"+ uniqueCommandFile, uniqueTmpFldrName);
7776
listener.getLogger()
7877
.println("#################### Starting command output ####################");
79-
return matlabLauncher.pwd(uniqeTmpFolderPath).join();
78+
return matlabLauncher.pwd(workspace).join();
8079

8180
} catch (Exception e) {
8281
listener.getLogger().println(e.getMessage());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
124124

125125
try {
126126
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
127-
uniqueCommandFile, uniqueTmpFldrName);
127+
"cd('"+ uniqeTmpFolderPath.getRemote() +"');"+ uniqueCommandFile, uniqueTmpFldrName);
128128
launcher.launch().pwd(uniqeTmpFolderPath).envs(envVars);
129129
listener.getLogger()
130130
.println("#################### Starting command output ####################");
131-
return matlabLauncher.pwd(uniqeTmpFolderPath).join();
131+
return matlabLauncher.join();
132132

133133
} catch (Exception e) {
134134
listener.getLogger().println(e.getMessage());

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ public void verifyMATLABlaunchedWithDefaultArguments() throws Exception {
136136
jenkins.assertLogContains("run_matlab_command", build);
137137
}
138138

139+
/*
140+
* Test To verify MATLAB is launched always from build workspace.
141+
*
142+
*/
143+
144+
@Test
145+
public void verifyMATLABlaunchedfromWorkspace() throws Exception {
146+
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2017a"));
147+
project.getBuildWrappersList().add(this.buildWrapper);
148+
scriptBuilder.setMatlabCommand("pwd");
149+
project.getBuildersList().add(this.scriptBuilder);
150+
FreeStyleBuild build = project.scheduleBuild2(0).get();
151+
String workspace = build.getWorkspace().getName();
152+
jenkins.assertLogContains(workspace, build);
153+
}
154+
139155
/*
140156
* Test to verify if job fails when invalid MATLAB path is provided and Exception is thrown
141157
*/

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,25 @@ public void verifyMATLABPathNotSet() throws Exception {
4242
WorkflowRun build = project.scheduleBuild2(0).get();
4343
j.assertLogContains("MATLAB_ROOT", build);
4444
}
45+
46+
/*
47+
* Verify MATLAB gets invoked from workspace.
48+
*/
49+
50+
@Test
51+
public void verifyMATLABstartsInWorkspace() throws Exception {
52+
DumbSlave s = j.createOnlineSlave();
53+
project.setDefinition(new CpsFlowDefinition(
54+
"node('!master') { runMATLABCommand(command: 'pwd')}",
55+
true));
4556

57+
FilePath workspace = s.getWorkspaceFor(project);
58+
String workspaceName = workspace.getName();
59+
WorkflowRun build = project.scheduleBuild2(0).get();
60+
61+
j.assertLogContains(workspaceName, build);
62+
}
63+
4664
/*
4765
* Verify MATLAB is invoked when valid MATLAB is in PATH.
4866
*

0 commit comments

Comments
 (0)